Sending email from asp.net using Gmail SMTP OAUTH

Sagar

I just want to implement one sample mail sending application. I have done lot of research for this. From all the corners I am getting same kind of solution. But that is not working for me.I am unable to find my mistake. I am using below code

protected void SendEmail(object sender, EventArgs e)
{
    string to = txtTo.Text;
    string from = txtEmail.Text;
    string subject = txtSubject.Text;
    string body = txtBody.Text;
    using (MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text))
    {
        mm.Subject = txtSubject.Text;
        mm.Body = txtBody.Text;
        if (fuAttachment.HasFile)
        {
            string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
            mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
        }
        mm.IsBodyHtml = false;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mm);
        ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
    }
}

And getting the exception like below

enter image description here

please suggest me how can I solve this issue.

Thanks in advance.

Chintan Udeshi

Assuming that you are using a correct Gmail credentials for the account with which you are sending emails. You need to turn on "less secure apps" setting using the below link: https://www.google.com/settings/u/1/security/lesssecureapps

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

PHPmailer not sending emails from localhost using gmail's SMTP

分類Dev

Sending email using luasocket smtp and ssl

分類Dev

Sending an Entity on email using Mailer ASP.net

分類Dev

Can I authenticate SMTP using SwiftMailer without sending an email

分類Dev

Yii2 SwiftMailer sending email via remote smtp server (gmail)

分類Dev

Sending Email in Laravel Using Swift Mailer without Gmail

分類Dev

Gmail PHP API Sending Email

分類Dev

Getting error while sending email through Gmail

分類Dev

GMAIL API sending email with attachment in c#

分類Dev

Setting gmail as default for sending files via email

分類Dev

phpmailer working on localhost but when i upload it on my ubuntu server it gives me error and mail is not sending(I am using gmail smtp)

分類Dev

SMTP to Gmail Authenticated Relay not working email stuck in queue

分類Dev

jboss5 sending email over smtp + tls

分類Dev

Sending email with attachment using Maven

分類Dev

Problem sending email using ssmtp

分類Dev

Sending large amount of data from view to controller in asp.net

分類Dev

Sending email from the iOS sdk

分類Dev

Really strange Net::SMTP error for certain email

分類Dev

Email for user confirmation not sending in production. Rails, Heroku, Gmail

分類Dev

Inline styles for table in html email for Gmail and sending with PHPMailer

分類Dev

PHP send email BCC & CC using SMTP

分類Dev

How to get subject of email from gmail using google API using python?

分類Dev

Gmail oauth received on date using PHP

分類Dev

How Can i send the email from the MVC4 to my gmail without using my password?

分類Dev

Send an HTML email using the Gmail API

分類Dev

Send Email via Gmail from Command Prompt

分類Dev

Extract phone numbers from Gmail email body

分類Dev

Should I need to open port 25 for sending email using ses from ec2 instance

分類Dev

Sending email with multiple attachments using smpt

Related 関連記事

  1. 1

    PHPmailer not sending emails from localhost using gmail's SMTP

  2. 2

    Sending email using luasocket smtp and ssl

  3. 3

    Sending an Entity on email using Mailer ASP.net

  4. 4

    Can I authenticate SMTP using SwiftMailer without sending an email

  5. 5

    Yii2 SwiftMailer sending email via remote smtp server (gmail)

  6. 6

    Sending Email in Laravel Using Swift Mailer without Gmail

  7. 7

    Gmail PHP API Sending Email

  8. 8

    Getting error while sending email through Gmail

  9. 9

    GMAIL API sending email with attachment in c#

  10. 10

    Setting gmail as default for sending files via email

  11. 11

    phpmailer working on localhost but when i upload it on my ubuntu server it gives me error and mail is not sending(I am using gmail smtp)

  12. 12

    SMTP to Gmail Authenticated Relay not working email stuck in queue

  13. 13

    jboss5 sending email over smtp + tls

  14. 14

    Sending email with attachment using Maven

  15. 15

    Problem sending email using ssmtp

  16. 16

    Sending large amount of data from view to controller in asp.net

  17. 17

    Sending email from the iOS sdk

  18. 18

    Really strange Net::SMTP error for certain email

  19. 19

    Email for user confirmation not sending in production. Rails, Heroku, Gmail

  20. 20

    Inline styles for table in html email for Gmail and sending with PHPMailer

  21. 21

    PHP send email BCC & CC using SMTP

  22. 22

    How to get subject of email from gmail using google API using python?

  23. 23

    Gmail oauth received on date using PHP

  24. 24

    How Can i send the email from the MVC4 to my gmail without using my password?

  25. 25

    Send an HTML email using the Gmail API

  26. 26

    Send Email via Gmail from Command Prompt

  27. 27

    Extract phone numbers from Gmail email body

  28. 28

    Should I need to open port 25 for sending email using ses from ec2 instance

  29. 29

    Sending email with multiple attachments using smpt

ホットタグ

アーカイブ