【问题标题】:Mail code works in localhost but not on the URL website afterwards邮件代码在 localhost 中有效,但之后在 URL 网站上无效
【发布时间】:2019-09-01 20:55:47
【问题描述】:

我在 Visual Studio 2017 上为 ASP.NET 核心制作了一个 Web 应用程序。它有一个联系选项,用户可以在其中向我发送电子邮件。当我收到反馈时,它在 localhost 中完美运行。当我使用 Azure DevOps 在门户中的 azure 应用服务上构建/发布时,我的网站在其 URL 处失去了电子邮件选项的功能。我使用 MailKit 编写了电子邮件代码,如果你们有更好的选择,请告诉我!谢谢你。

        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 目前无法处理此请求。

【问题讨论】:

    标签: visual-studio-2017 azure-devops smtp azure-web-app-service mailkit


    【解决方案1】:

    问题是您使用的是 gmail。 GMail 仅允许您使用 SMTP/IMAP/POP3 进行身份验证您已通过网络从特定设备进行身份验证。

    【讨论】:

    • 哦!谢谢!你建议我能做什么?我对这个话题不太了解
    猜你喜欢
    • 2018-05-15
    • 2017-12-29
    • 2016-11-14
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 2019-02-17
    • 2016-12-16
    相关资源
    最近更新 更多