0 votes
by (8.4k points)
edited

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
by (58.9k points)
edited
 
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.

...