Mail with base64 encoded attachments

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


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,890 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;


        // save the message

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

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