我正在开发一个 C# 项目,我正在构建自己的 SMTP 服务器。它基本上可以工作,但我现在正试图让多个收件人被发送,但我收到一个错误。
我从发件人域获取 MX 记录,然后我使用 MX 记录尝试向多个收件人发送电子邮件。如果我用同一个域做两个收件人,它工作正常,如果两个收件人有不同的域,我会得到以下响应:
Failed to send email. General Exception: Error in processing. The server response was: 4.3.0 Multiple destination domains per transaction is unsupported. Please
please
响应结束后就什么都没有了。
以下是我获取 MX 记录的方式:
字符串[] mxRecords = mxLookup.getMXRecords(Classes.CommonTasks.getDomainFromEmail(domain));
public string[] getMXRecords(string domain)
{
DnsLite dl = new DnsLite(library);
ArrayList dnsServers = getDnsServers();
dl.setDnsServers(dnsServers);
ArrayList results = null;
string[] retVal = null;
results = dl.getMXRecords(domain);
if (results != null)
{
retVal = new string[results.Count];
int counter = 0;
foreach (MXRecord mx in results)
{
retVal[counter] = mx.exchange.ToString();
counter++;
}
}
return retVal;
}
以下是我发送电子邮件的方式。
if (mxRecords != null)
{
MailMessage composedMail = new MailMessage();
composedMail.From = new MailAddress(message.EmailFromAddress);
//MailAddressCollection test = new MailAddressCollection();
//composedMail.To = test;
composedMail = addRecipientsToEmail(composedMail, message.emailRecipients);
composedMail.Subject = message.subject;
composedMail.Body = message.EmailBody;
if (message.contentType.ToString().Contains("text/html"))
{
composedMail.IsBodyHtml = true;
}
SmtpClient smtp = new SmtpClient(mxRecords[0]);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Port = 25;
if (Configuration.emailConfig.useSmtpMaxIdleTime)
{
smtp.ServicePoint.MaxIdleTime = 1;
}
library.logging(methodInfo, string.Format("Sending email via MX Record: {0}", mxRecords[0]));
smtp.Send(composedMail);
updateEmailStatus(message.emailID, EmailStatus.Sent);
library.logging(methodInfo, string.Format("Successfully sent email ID: {0}", message.emailID));
}
else
{
string error = string.Format("No MX Record found for domain: {0}", domain);
library.logging(methodInfo, error);
library.setAlarm(error, CommonTasks.AlarmStatus.Warning, methodInfo);
}
这看起来好像是谷歌限制完成的事情,但我找不到解决方法,除了分别为每个收件人发送电子邮件。
如果有任何用处,这两个域是谷歌应用域。
感谢您的任何帮助,您可以提供。