David B.
David B.

Reputation: 59

Mail code works in localhost but not on the URL website afterwards

I made a web application on visual studio 2017 for ASP.NET core. It has a contact option where users send me an email. It works perfectly in localhost as I receive the feedback. When I build/release using Azure DevOps onto azure app services in the portal my website at its URL loses the functionality of the email option. I wrote the email code using MailKit, if you guys have a better option that works let me know! Thank you.

        var message = new MimeMessage();
        message.From.Add(new MailboxAddress(inputEmail));
        message.To.Add(new MailboxAddress("myemail"));
        message.Subject = "Message from: " + inputName;
        message.Body = new TextPart("plain")
        {
            Text = inputMessage
        };
        using (var client = new SmtpClient())
        {
            client.Connect("smtp.gmail.com", 587, false);
            client.Authenticate("email", "password");
            client.Send(message);
            client.Disconnect(true);
        };
        return RedirectToAction("Index");

mywebsite.azurewebsites.net is currently unable to handle this request.

Upvotes: 0

Views: 391

Answers (1)

jstedfast
jstedfast

Reputation: 38538

The problem is that you are using gmail. GMail only allows you to authenticate using SMTP/IMAP/POP3 after you've authenticated via the web from a particular device.

Upvotes: 1

Related Questions