我试着把工资单发给我们所有的员工,但是有一堆gmail账户的邮件被延迟或屏蔽了。
我已经使用GSuite帐户进行了测试,并收到了电子邮件,但在电子邮件的“原始电子邮件”视图中,我看到以下行:
ARC-Authentication-Results: i=1; mx.google.com;
spf=permerror (google.com: permanent error in processing during lookup
of no-reply@our-domain.com.au: mail.optusnet.com.au not found)
smtp.mailfrom=no-reply@our-domain.com.au和
Received-SPF: permerror (google.com: permanent error in processing during
lookup of no-reply@our-domain.com.au: mail.optusnet.com.au not found)
client-ip=000.000.00.000;我们有一个有效的SPF记录,允许通过O365从我们的服务器发送电子邮件。
这是我用来发送电子邮件的类。我正在使用一个Parallel.ForEach循环来发送电子邮件。在生产中最大线程数为3或4。
public class EmailService : IDisposable
{
public const string DefaultFromAddress = "no-reply@our-domain.com.au";
private const string Office365Host = "smtp.office365.com";
private const int Office365Port = 587;
private const string Office365UserName = "O365_App_UserName";
private const string Office365Password = @"--Password--";
//private readonly SmtpClient _smtpClient;
private SmtpClient _smtpClient;
private readonly Logger _logger;
public EmailService()
{
_logger = LogManager.GetCurrentClassLogger();
_smtpClient = new SmtpClient
{
Host = Office365Host,
Port = Office365Port,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(Office365UserName, Office365Password),
DeliveryMethod = SmtpDeliveryMethod.Network,
EnableSsl = true,
TargetName = "STARTTLS/smtp.office365.com"
};
}
public bool SendEmail(MailMessage message)
{
try
{
_smtpClient.Send(message);
}
catch (Exception ex)
{
_logger.Error(ex, $"Failed to send email: from: {message.From.Address}, to:{message.To.First()}. more details:{ex.InnerException}");
return false;
}
return true;
}
public void Dispose()
{
_smtpClient.Dispose();
}
}以下是发送编写的消息的循环中的代码:
using (EmailService emailService = new EmailService())
{
employee.EmailSent = emailService.SendEmail(mailMessage);
}这里我漏掉了什么?我们也需要对mail.optusnet.com.au的SPF记录做些什么吗?
任何其他的建议都将不胜感激。谢谢
发布于 2019-02-13 11:39:33
我找到了我的问题的解决方案。经过挖掘和测试,我的代码没有任何问题,这与DNS记录有关。SPF类型记录已被TXT类型记录取代。谷歌似乎更安全,正在检查SPF类型,在该条目中列出的每个域上都失败了。当我将它们从记录中删除时,一个新的域名出现了。然后,我们完全删除了SPF类型,错误也消失了。
https://stackoverflow.com/questions/54564683
复制相似问题