Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
707 views
in Technique[技术] by (71.8m points)

smtp - My Gmail API suddenly stopped sending emails through my application in ASP.Net

A developer is passed in with values and this method used to work but stopped suddenly. I dont recall changing anything that would have a direct impact in the Gmail API. Please help I need to show this to a employer tomorrow.

...

 public void SendEmail(Developer developer)
    {
        var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
        var loggedInEmployer = _context.Employers.Where(e => e.IdentityUserId == 
        userId).SingleOrDefault();

        var fromEmail = loggedInEmployer.Email;
        var toEmail = developer.Email;
        var fromAddress = new MailAddress(fromEmail, loggedInEmployer.UserName);
        var toAddress = new MailAddress(toEmail, developer.UserName);
        string fromPassword = MyKeys.passcode;
        const string subject = "Hired On DevWorks";
        string body = "Congratulations " + loggedInEmployer.UserName + " Has Hired you for contract at " + loggedInEmployer.CompanyName + "!";

        SmtpClient smtp = new SmtpClient
        {
            Host = "smtp.gmail.com",
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
            Timeout = 20000
        };
        using (var message2 = new MailMessage(fromAddress, toAddress)
        {
            Subject = subject,
            Body = body
        })
        {
            smtp.Send(message2);
        }
    }

...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Turns out I recently changed my Gmail password recently. A simple mistake but a common one.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...