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










share|improve this question






















  • 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
    2 days ago

















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










share|improve this question






















  • 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
    2 days ago















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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
    2 days ago




















  • 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
    2 days ago


















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
2 days ago






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
2 days ago














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






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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






    share|improve this answer

























      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






      share|improve this answer























        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 20:21









        György Gulyás

        1508




        1508






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python