Mail with base64 encoded attachments

0 votes
asked Aug 30, 2013 by Rebex KB (8,210 points)
edited Aug 30, 2013

Hello,

could you advise what is the right way to create a mail with base64 encoded attachments with Rebex Secure Mail component?

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Aug 30, 2013 by Tomas Knopp (58,580 points)
edited Aug 30, 2013
 
Best answer

Just use Attachment class constructor and then set the TransferEncoding to base64 as in the example below:

        var message = new MailMessage
        {
            From = "from",
            To = "to",
            Subject = "subject",
            BodyText = "email body"
        };

        Attachment attachment = new Attachment(@"C:\MyData\file.txt", "file.txt");
        attachment.TransferEncoding = TransferEncoding.Base64;

        message.Attachments.Add(attachment);

        // save the message
        message.Save(@"C:\MyData\mail-with-base64-attachment.eml");

        // or send the message
        Smtp smtp = new Smtp();
        smtp.Connect("server");
        smtp.Login("username", "password");
        smtp.Send(message);

The component will handle the base64 conversion automatically. Apart from Base64 Transfer Encoding, you can use QuotedPrintable, Binary, SevenBit and EightBit Transfer Encoding.

...