Sending email with attachments from C#, attachments arrive as Part 1.2 in Thunderbird

Posted by Jon on Stack Overflow See other posts from Stack Overflow or by Jon
Published on 2010-05-13T10:16:10Z Indexed on 2010/05/13 16:24 UTC
Read the original article Hit count: 480

Filed under:
|
|
|

I have a C# application which emails out Excel spreadsheet reports via an Exchange 2007 server using SMTP. These arrive fine for Outlook users, but for Thunderbird and Blackberry users the attachments have been renamed as "Part 1.2".

I found this article which describes the problem, but doesn't seem to give me a workaround. I don't have control of the Exchange server so can't make changes there. Is there anything I can do on the C# end? I have tried using short filenames and HTML encoding for the body but neither made a difference.

My mail sending code is simply this:

    public static void SendMail(string recipient, string subject, string body, string attachmentFilename)
    {
        SmtpClient smtpClient = new SmtpClient();
        NetworkCredential basicCredential = new NetworkCredential(MailConst.Username, MailConst.Password);
        MailMessage message = new MailMessage();
        MailAddress fromAddress = new MailAddress(MailConst.Username);

        // setup up the host, increase the timeout to 5 minutes
        smtpClient.Host = MailConst.SmtpServer;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = basicCredential;
        smtpClient.Timeout = (60 * 5 * 1000);

        message.From = fromAddress;
        message.Subject = subject;
        message.IsBodyHtml = false;
        message.Body = body;
        message.To.Add(recipient);

        if (attachmentFilename != null)
            message.Attachments.Add(new Attachment(attachmentFilename));

        smtpClient.Send(message);
    }

Thanks for any help.

© Stack Overflow or respective owner

Related posts about c#

Related posts about smtp