我正在建立我自己的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