【发布时间】:2021-07-20 20:18:14
【问题描述】:
我们有一个 azure 应用服务,突然间我们看到了这个错误:
System.Net.Mail.SmtpException: Insufficient system storage. The server response was: 4.3.1 Out of memory at System.Net.Mail.SendMailAsyncResult.End(IAsyncResult result) at System.Net.Mail.SmtpClient.SendMailCallback(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at
我们已向发送电子邮件的提供商提交了一张票,但他们说他们没有发现问题。现在我们认为我们在上一个版本中推送了一些可能导致问题的东西。当然,我们目前还没有发现任何东西。
只是好奇其他人是否有这些问题以及最终结果是什么?
我们还在 Azure 中的其他应用服务上使用了此代码,但这些服务由不同的客户(不同的实例)控制。现在遇到问题的是一位新客户,我们已将代码推送到一周前的星期一。不过上周似乎一切都很好。
这是我们的 SMTP 代码:
/// <summary>
/// Send an email via code. All email's with attachments are sent through code.
/// </summary>
/// <param name="email">Email Data</param>
/// <param name="smtpServer">The SMTP server.</param>
/// <returns>
/// Task
/// </returns>
private async Task SendSMTPEmail(EmailDTO email, SMTPServerDTO smtpServer)
{
SmtpClient smtp = null;
if (email == null)
{
throw new ArgumentNullException(nameof(email));
}
if (smtpServer == null)
{
throw new ArgumentNullException(nameof(smtpServer));
}
if (!smtpServer.Port.HasValue)
{
smtp = new SmtpClient(smtpServer.HostName);
}
else
{
smtp = new SmtpClient(smtpServer.HostName, smtpServer.Port.Value);
}
// Sets the NetworkCredential if a user name and password is required
if (!string.IsNullOrWhiteSpace(smtpServer.Username) && !string.IsNullOrWhiteSpace(smtpServer.Password))
{
smtp.Credentials = new System.Net.NetworkCredential(smtpServer.Username, smtpServer.Password);
}
MailMessage mailMessage = new MailMessage
{
From = new MailAddress(email.FromAddress)
};
foreach (string toAddress in email.ToAddresses)
{
mailMessage.To.Add(new MailAddress(toAddress));
}
foreach (string ccAddress in email.CCAddresses)
{
mailMessage.CC.Add(ccAddress);
}
foreach (string bccAddress in email.BCCAddresses)
{
mailMessage.Bcc.Add(bccAddress);
}
if (!string.IsNullOrWhiteSpace(email.ReplyToAddress))
{
mailMessage.ReplyToList.Add(email.ReplyToAddress);
}
mailMessage.Subject = email.Subject;
mailMessage.Body = email.Body;
if (!string.IsNullOrWhiteSpace(email.Importance))
{
email.Importance = email.Importance.ToLower();
}
switch (email.Importance)
{
case "low":
mailMessage.Priority = MailPriority.Low;
break;
case "normal":
mailMessage.Priority = MailPriority.Normal;
break;
case "high":
mailMessage.Priority = MailPriority.High;
break;
default:
mailMessage.Priority = MailPriority.Normal;
break;
}
if (!string.IsNullOrWhiteSpace(email.Sensitivity))
{
mailMessage.Headers.Add("Sensitivity", email.Sensitivity);
}
else
{
mailMessage.Headers.Add("Sensitivity", EmailSensitivityConstants.CompanyConfidential);
}
foreach (EmailAttachmentDTO emailAttachment in email.Attachments)
{
byte[] attachmentData = Convert.FromBase64String(emailAttachment.FileData);
MemoryStream memoryStream = new MemoryStream(attachmentData);
System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(memoryStream, emailAttachment.FileName);
mailMessage.Attachments.Add(attachment);
}
await smtp.SendMailAsync(mailMessage).ConfigureAwait(false);
}
【问题讨论】:
标签: azure-web-app-service smtpclient