简体   繁体   中英

Send MIME-encoded file as e-mail in C#

I've got the problem that I have a MIME-encoded file with all relevant mail information (subject, from, to, ...) and want to send it over a defined SMTP server via C#.

I've looked at the MailMessage class and searched for a solution, but I couldn't find something fitting. Are you able to help me?

Thanks, Matthias

The current version of the standard .NET framework does not support it AFAIK. However you will find such functionality in most third-party mail components.

Following code uses our Rebex Mail library.

using Rebex.Net; // Smtp class
using Rebex.Mail; // contains the MailMessage and other classes 

// create an instance of MailMessage 
MailMessage message = new MailMessage();

// load the message from a local disk file 
message.Load("c:\\message.eml");

Smtp.Send(message, "smtp.example.org");

The code is taken from Rebex SMTP Tutorial and Rebex MailMessage tutorial .

You can do it easily accomplish this task using Mail.dll email component :

IMail email = new CreateFromEmlFile("c:\\email.eml");

using(Smtp smtp = new Smtp())
{
    smtp.Connect("smtp.company.com");
    smtp.Ehlo(HeloType.EhloHelo, "Mail.dll");
    smtp.Login("user", "password");

    smtp.SendMessage(email);

    smtp.Close(false);
}

Please note that Mail.dll is a commercial product that I've created.

In a word "no".

You will have to parse the file, extract the data, and set the various properties on the MailMessage object.

If you are looking to create or load a MailMessage object from mime content, there isn't any way to do that natively in the Framework.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM