Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email not send if attachment used [sf#17] #16

Open
nilnull opened this issue Apr 15, 2019 · 5 comments
Open

Email not send if attachment used [sf#17] #16

nilnull opened this issue Apr 15, 2019 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@nilnull
Copy link
Owner

nilnull commented Apr 15, 2019

Reported by rkmoray on 2018-07-25 17:42 UTC
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);
@nilnull
Copy link
Owner Author

nilnull commented Apr 15, 2019

Commented by dimex on 2019-04-14 12:45 UTC
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);
			}
		...

@nilnull nilnull added this to the 1.0 milestone Apr 15, 2019
@nilnull nilnull changed the title Email not send if attachment used Email not send if attachment used [sf#17] Apr 15, 2019
@nilnull
Copy link
Owner Author

nilnull commented Apr 15, 2019

Commented by nilnull on 2019-04-14 14:46 UTC
May I ask if you have any explenation for this?

@nilnull
Copy link
Owner Author

nilnull commented Apr 15, 2019

Commented by dimex on 2019-04-14 18:36 UTC
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.

@nilnull
Copy link
Owner Author

nilnull commented Apr 15, 2019

Commented by nilnull on 2019-04-15 06:35 UTC
Great, would you be kind enough to do a pull request?

@nilnull nilnull added bug Something isn't working help wanted Extra attention is needed labels Sep 4, 2019
@nilnull nilnull modified the milestones: 1.0, 2.0 Feb 4, 2022
@carlosbet
Copy link
Contributor

This @dimex proposal already been added to the code by @mwidev.

8143f4d

I think that this issue should be closed.
Thanks, @dimex and @mwidev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants