Menu

#17 Email not send if attachment used

1.0
closed
None
2019-04-16
2018-07-25
No

My issue at the moment,is if an attachment is being used, the email does not get send, and there is no error message. The file name is correct, I have verified that. Whith this code I get no email, but no error message as well.
Here is an example
string strdtfile = DateTime.Now.ToString("yyyyMMddHHmmss");
string FilePath = @Server.MapPath("~/Temp/" + strdtfile + ".pdf");
currentReport.ExportToPdf(FilePath);
var mymessage = new MimeMailMessage();
mymessage.From = new MimeMailAddress(Mail);
mymessage.Subject = "Web Purchase Receipt " + DateTime.Now.ToString("yyyyMMdd");
mymessage.To.Add(Session["email"].ToString());
mymessage.Body = "";
mymessage.IsBodyHtml = true;
mymessage.To.Add(Session["email"].ToString());
var mailer = new MimeMailer(Host, 465)
{
User = User,
Password = Pass,
EnableImplicitSsl = true,
AuthenticationMode = AuthenticationType.Base64
};

        mymessage.Attachments.Add(new MimeAttachment(FilePath));

        ((SmtpSocketClient)mailer).SslType = SslMode.Ssl;

        mailer.SendCompleted += SendCompleted;
        mailer.SendMailAsync(mymessage);

Discussion

  • Dmitry N

    Dmitry N - 2019-04-14

    Had the same issue, mail server reported: "554 Too long line was received" when I tried to add an attachment.

    Fixed it by adding "\r\n" to stream chunks in SmtpSocketClient.cs, at the end of SendAttachments() method:

    ...
    
              char[] bufln = new char[2] { '\r', '\n' };
    
                while (num > 0)
                {                   
                    _con.SendData(Encoding.ASCII.GetChars(fbuf, 0, num), 0, num);
                    _con.SendData(bufln, 0, 2);   // <--------
                    num = cs.Read(fbuf, 0, 2048);
                }
            ...
    
     
    • Araz Farhang Dareshuri

      May I ask if you have any explenation for this?

       
      • Dmitry N

        Dmitry N - 2019-04-14

        Attachment is sent as a base64-encoded string and it looks like some email servers (hMailServer in my case) have limits for string length . So basically I just split one huge line to smaller parts.

         
        • Araz Farhang Dareshuri

          Great, would you be kind enough to do a pull request?

           
  • Araz Farhang Dareshuri

    • status: open --> accepted
    • assigned_to: Araz Farhang Dareshuri
     
  • Araz Farhang Dareshuri

    • status: accepted --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.