c# - 通过 Google 向多个收件人发送电子邮件

标签 c# email smtp

我正在开发一个 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);
                    }

这看起来似乎是 Google 限制执行的操作,但除了为每个收件人单独发送电子邮件之外,我找不到解决方法。

如果有任何用处,这两个域都是谷歌应用程序域。

感谢您提供的任何帮助。

最佳答案

看来你并不孤单。看看这个。

:

“根据我的调查和研究,我相信发生的情况是您的系统直接连接到传送服务器 (aspmx.l.google.com)。由于这是传送服务器,因此它不允许:

  1. 传送到未在 Google 上配置的帐户(即未经身份验证的转发)。

  2. 在同一 SMTP session 中传送到多个不同的域。

第二个对我们来说很重要。从本月初(2012年5月)开始,我们的服务器设置进行了调整,这意味着我们的交付服务器严格执行不允许多域的规则。有两种方法可以解决这个问题。第一个是在单独的 smtp session 上发送到单独的域,第二个是使用 smtp.gmail.com 代替 aspmx.l.google.com。”

http://productforums.google.com/forum/#!topic/apps/jEUrvTd1S_w

关于c# - 通过 Google 向多个收件人发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19506750/

相关文章:

c# - 将 IEnumerable<byte[]> 转换为 byte[]

python - 使用 python imap 和电子邮件包获取电子邮件的正文

dns - SPF 记录中的 DNS 查找过多

java - 为什么 SMTP 服务器收不到 DATA 命令?

python - Python 的 SMTP AUTH 扩展问题

c - 尝试使用 C 程序通过 SMTP 与电子邮件服务器通信

c# - 动态程序集过多

C# - 反序列化列表<String>

c# - 通过 MAPI32 将 HTML 嵌入到电子邮件中

android - 从 Android 发送附件时如何添加 .pdf 扩展名?