【问题标题】:Send Email From Azure Function App Without using SendGrid and Office 365不使用 SendGrid 和 Office 365 从 Azure Function App 发送电子邮件
【发布时间】:2019-08-02 13:05:56
【问题描述】:

我需要在不使用 sendgrid 和 office365 的情况下从 Azure Function 应用程序发送电子邮件。

使用outlook和Gmail smtp,函数报错

using System;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.Configuration;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;


public static void Run(Stream myBlob, string name, ILogger log, ExecutionContext context)
{
    log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");

    string fromEmail = System.Environment.GetEnvironmentVariable("SmtpUser");
    string toEmail = "abc@gmail.com";
    int smtpPort = Int32.Parse(System.Environment.GetEnvironmentVariable("SmtpPort"));
    bool smtpEnableSsl = true;
    string smtpHost = System.Environment.GetEnvironmentVariable("SmtpHost"); // your smtp host
    string smtpUser = System.Environment.GetEnvironmentVariable("SmtpUser"); // your smtp user
    string smtpPass = System.Environment.GetEnvironmentVariable("SmtpPassword"); // your smtp password
    string subject = System.Environment.GetEnvironmentVariable("EmailSubject");
    string message = "Hello, you are recieving message from Azure Function /n Thanks, /n Pooja";

    log.LogInformation($" Pass : {smtpPort} : Email: {fromEmail} : Host: {smtpHost} : Subject : {subject}");


    SmtpClient client = new SmtpClient();
    client.UseDefaultCredentials = false;
    client.Port = smtpPort;
    client.EnableSsl = smtpEnableSsl;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.Host = smtpHost;
    client.Credentials = new System.Net.NetworkCredential(smtpUser, smtpPass);

    MailMessage mail = new MailMessage();
    mail.Subject = subject;
    mail.From = new MailAddress(fromEmail);
    mail.Body=message;
    mail.To.Add(new MailAddress(toEmail));

    try{
        client.Send(mail);

        log.LogInformation("Email sent");

    }

    catch(Exception ex){
        log.LogInformation(ex.ToString());
    }

}

System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 Authentication Required。

【问题讨论】:

标签: azure azure-functions azure-blob-storage azure-function-app


【解决方案1】:

由于公共云服务 IP 和滥用的可能性。因此,Azure 计算 IP 地址块被添加到公共块列表(例如 Spamhaus PBL)中。此政策没有例外。”

到目前为止,在 Azure Web App 上使用 EMAIL 功能的唯一方法是通过 SMTP 中继。 SendGrid 等第三方服务提供此类服务。

在 Azure Web 应用架构中,实际的 Web 应用位于通用前端之后,这些前端由该数据中心上托管的所有站点共享。该数据中心上托管的某个站点可能正在发送 SPAM 电子邮件,并且该 IP 地址可能会被 MAIL 服务器列入黑名单。因此,从该地址发送的电子邮件将被邮件服务器拒绝或视为垃圾邮件

【讨论】:

  • 我同意你的观点,但很想看到这方面的来源。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-24
  • 1970-01-01
  • 1970-01-01
  • 2022-09-24
  • 2020-03-20
  • 2016-04-23
  • 2019-12-22
相关资源
最近更新 更多