Search code examples
c#filesmtpmimeemail

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


Solution

  • 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.