Send Email with attached Pdf problem in asp.net mvc 5
up vote
0
down vote
favorite
I am trying to send email with attached pdf, my pdf is in byte array. and when i try to send mail (without pdf) it shows
Message = The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
my code is `string senderEmail = System.Configuration.ConfigurationManager.AppSettings["SenderEmail"].ToString();
string senderPassword = System.Configuration.ConfigurationManager.AppSettings["SenderPassword"].ToString();
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Timeout = 100000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(senderEmail, senderPassword);
MailMessage mailMassege = new MailMessage(senderEmail, toEmail, subject, body);
mailMassege.IsBodyHtml = true;
mailMassege.BodyEncoding = Encoding.UTF8;
client.Send(mailMassege);`
and my pdf is in byte array
byte applicationPDFData = actionResult.BuildPdf(ControllerContext);
System.IO.File.WriteAllBytes(filePath + "/hello.pdf", applicationPDFData);
I want to to send mail with this pdf.
thanks in advance
c# asp.net asp.net-mvc smtp
add a comment |
up vote
0
down vote
favorite
I am trying to send email with attached pdf, my pdf is in byte array. and when i try to send mail (without pdf) it shows
Message = The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
my code is `string senderEmail = System.Configuration.ConfigurationManager.AppSettings["SenderEmail"].ToString();
string senderPassword = System.Configuration.ConfigurationManager.AppSettings["SenderPassword"].ToString();
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Timeout = 100000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(senderEmail, senderPassword);
MailMessage mailMassege = new MailMessage(senderEmail, toEmail, subject, body);
mailMassege.IsBodyHtml = true;
mailMassege.BodyEncoding = Encoding.UTF8;
client.Send(mailMassege);`
and my pdf is in byte array
byte applicationPDFData = actionResult.BuildPdf(ControllerContext);
System.IO.File.WriteAllBytes(filePath + "/hello.pdf", applicationPDFData);
I want to to send mail with this pdf.
thanks in advance
c# asp.net asp.net-mvc smtp
have you seen this? stackoverflow.com/questions/20906077/…
– derloopkat
Nov 10 at 19:32
the code is same and i also close 2 step verification but same error
– MD MASUM
Nov 10 at 19:40
It's just a guess, but on your google account, are the less secure apps enabled?
– LeviTheOne
Nov 10 at 19:51
I can see that the error is about Authentication. Try using port 465. You can find more details here: support.google.com/a/answer/176600?hl=en Also, will it send the email without attachment?
– Sergiu Muresan
Nov 14 at 13:42
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to send email with attached pdf, my pdf is in byte array. and when i try to send mail (without pdf) it shows
Message = The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
my code is `string senderEmail = System.Configuration.ConfigurationManager.AppSettings["SenderEmail"].ToString();
string senderPassword = System.Configuration.ConfigurationManager.AppSettings["SenderPassword"].ToString();
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Timeout = 100000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(senderEmail, senderPassword);
MailMessage mailMassege = new MailMessage(senderEmail, toEmail, subject, body);
mailMassege.IsBodyHtml = true;
mailMassege.BodyEncoding = Encoding.UTF8;
client.Send(mailMassege);`
and my pdf is in byte array
byte applicationPDFData = actionResult.BuildPdf(ControllerContext);
System.IO.File.WriteAllBytes(filePath + "/hello.pdf", applicationPDFData);
I want to to send mail with this pdf.
thanks in advance
c# asp.net asp.net-mvc smtp
I am trying to send email with attached pdf, my pdf is in byte array. and when i try to send mail (without pdf) it shows
Message = The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
my code is `string senderEmail = System.Configuration.ConfigurationManager.AppSettings["SenderEmail"].ToString();
string senderPassword = System.Configuration.ConfigurationManager.AppSettings["SenderPassword"].ToString();
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Timeout = 100000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(senderEmail, senderPassword);
MailMessage mailMassege = new MailMessage(senderEmail, toEmail, subject, body);
mailMassege.IsBodyHtml = true;
mailMassege.BodyEncoding = Encoding.UTF8;
client.Send(mailMassege);`
and my pdf is in byte array
byte applicationPDFData = actionResult.BuildPdf(ControllerContext);
System.IO.File.WriteAllBytes(filePath + "/hello.pdf", applicationPDFData);
I want to to send mail with this pdf.
thanks in advance
c# asp.net asp.net-mvc smtp
c# asp.net asp.net-mvc smtp
asked Nov 10 at 19:12
MD MASUM
203
203
have you seen this? stackoverflow.com/questions/20906077/…
– derloopkat
Nov 10 at 19:32
the code is same and i also close 2 step verification but same error
– MD MASUM
Nov 10 at 19:40
It's just a guess, but on your google account, are the less secure apps enabled?
– LeviTheOne
Nov 10 at 19:51
I can see that the error is about Authentication. Try using port 465. You can find more details here: support.google.com/a/answer/176600?hl=en Also, will it send the email without attachment?
– Sergiu Muresan
Nov 14 at 13:42
add a comment |
have you seen this? stackoverflow.com/questions/20906077/…
– derloopkat
Nov 10 at 19:32
the code is same and i also close 2 step verification but same error
– MD MASUM
Nov 10 at 19:40
It's just a guess, but on your google account, are the less secure apps enabled?
– LeviTheOne
Nov 10 at 19:51
I can see that the error is about Authentication. Try using port 465. You can find more details here: support.google.com/a/answer/176600?hl=en Also, will it send the email without attachment?
– Sergiu Muresan
Nov 14 at 13:42
have you seen this? stackoverflow.com/questions/20906077/…
– derloopkat
Nov 10 at 19:32
have you seen this? stackoverflow.com/questions/20906077/…
– derloopkat
Nov 10 at 19:32
the code is same and i also close 2 step verification but same error
– MD MASUM
Nov 10 at 19:40
the code is same and i also close 2 step verification but same error
– MD MASUM
Nov 10 at 19:40
It's just a guess, but on your google account, are the less secure apps enabled?
– LeviTheOne
Nov 10 at 19:51
It's just a guess, but on your google account, are the less secure apps enabled?
– LeviTheOne
Nov 10 at 19:51
I can see that the error is about Authentication. Try using port 465. You can find more details here: support.google.com/a/answer/176600?hl=en Also, will it send the email without attachment?
– Sergiu Muresan
Nov 14 at 13:42
I can see that the error is about Authentication. Try using port 465. You can find more details here: support.google.com/a/answer/176600?hl=en Also, will it send the email without attachment?
– Sergiu Muresan
Nov 14 at 13:42
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You have to create an attachment and append it to the mail Attachemnts list.
here is an example:
byte applicationPDFData = actionResult.BuildPdf(ControllerContext);
Attachment attPDF = new Attachment(new MemoryStream(applicationPDFData), name);
EmailMessage emailMessage = new EmailMessage();
emailMessage.To.Add( new EmailRecipient( toEmail ) );
emailMessage.Subject = subject;
emailMessage.Body = body;
emailMessage.Attachments.Add( attPDF );
regrads
gy
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You have to create an attachment and append it to the mail Attachemnts list.
here is an example:
byte applicationPDFData = actionResult.BuildPdf(ControllerContext);
Attachment attPDF = new Attachment(new MemoryStream(applicationPDFData), name);
EmailMessage emailMessage = new EmailMessage();
emailMessage.To.Add( new EmailRecipient( toEmail ) );
emailMessage.Subject = subject;
emailMessage.Body = body;
emailMessage.Attachments.Add( attPDF );
regrads
gy
add a comment |
up vote
0
down vote
You have to create an attachment and append it to the mail Attachemnts list.
here is an example:
byte applicationPDFData = actionResult.BuildPdf(ControllerContext);
Attachment attPDF = new Attachment(new MemoryStream(applicationPDFData), name);
EmailMessage emailMessage = new EmailMessage();
emailMessage.To.Add( new EmailRecipient( toEmail ) );
emailMessage.Subject = subject;
emailMessage.Body = body;
emailMessage.Attachments.Add( attPDF );
regrads
gy
add a comment |
up vote
0
down vote
up vote
0
down vote
You have to create an attachment and append it to the mail Attachemnts list.
here is an example:
byte applicationPDFData = actionResult.BuildPdf(ControllerContext);
Attachment attPDF = new Attachment(new MemoryStream(applicationPDFData), name);
EmailMessage emailMessage = new EmailMessage();
emailMessage.To.Add( new EmailRecipient( toEmail ) );
emailMessage.Subject = subject;
emailMessage.Body = body;
emailMessage.Attachments.Add( attPDF );
regrads
gy
You have to create an attachment and append it to the mail Attachemnts list.
here is an example:
byte applicationPDFData = actionResult.BuildPdf(ControllerContext);
Attachment attPDF = new Attachment(new MemoryStream(applicationPDFData), name);
EmailMessage emailMessage = new EmailMessage();
emailMessage.To.Add( new EmailRecipient( toEmail ) );
emailMessage.Subject = subject;
emailMessage.Body = body;
emailMessage.Attachments.Add( attPDF );
regrads
gy
answered Nov 10 at 20:21
György Gulyás
1898
1898
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242500%2fsend-email-with-attached-pdf-problem-in-asp-net-mvc-5%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
have you seen this? stackoverflow.com/questions/20906077/…
– derloopkat
Nov 10 at 19:32
the code is same and i also close 2 step verification but same error
– MD MASUM
Nov 10 at 19:40
It's just a guess, but on your google account, are the less secure apps enabled?
– LeviTheOne
Nov 10 at 19:51
I can see that the error is about Authentication. Try using port 465. You can find more details here: support.google.com/a/answer/176600?hl=en Also, will it send the email without attachment?
– Sergiu Muresan
Nov 14 at 13:42