我正在建立我自己的SMTP服务器的C#项目。它基本上工作,但我现在试图让多个收件人被发送,但我收到一个错误。通过谷歌发送电子邮件给多个收件人
我从发件人域获取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记录:
的String [] mxRecords = mxLookup.getMXRecords(Classes.CommonTasks.getDomainFromEmail(域));
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);
}
这看起来就好像它是什么,谷歌从正在做限制,但我无法找到一个方法来解决了,除了单独发送的电子邮件的每个收件人。
如果它有任何用处,这两个域是谷歌应用程序域。
感谢您提供的任何帮助。
小评论,在SMTP。 gmail.com需要认证,所以你可能想使用另一台smtp服务器(如果可用) – Jacco