Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
749 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);
        }
    }

...

question from:https://stackoverflow.com/questions/65601467/my-gmail-api-suddenly-stopped-sending-emails-through-my-application-in-asp-net

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...