views:

189

answers:

3

Hi folks,

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

A: 

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.

Cheers!

Dave

dave wanta
A: 

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.

Martin Vobr
A: 

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.

Pawel Lesnikowski