Boardy
Boardy

Reputation: 36217

Sending email to multiple recipients via Google

I am working on an C# project where I am building my own SMTP server. It is basically working but I am now trying to get multiple recipients being sent but I am receiving an error.

I am getting the MX record from the senders domain and I am then using MX Record to try and send an email to multiple recipients. If I do two recipients with the same domain it works fine, if the two recipients have different domains, I then get the following response:

Failed to send email. General Exception: Error in processing. The server response was: 4.3.0 Multiple destination domains per transaction is unsupported.  Please

There is nothing after please that's the end of the response.

Below is how I am getting the MX Record:

string[] 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;
}

Below is how I am sending the email.

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);
                    }

This looks as if it is something that Google is restricting from being done but I can't find a way to work around out, other than to send the emails separately for each recipient.

If it's of any use, the two domains are google app domains.

Thanks for any help you can provide.

Upvotes: 2

Views: 1677

Answers (2)

lboshuizen
lboshuizen

Reputation: 2786

Sine you can send an email with a single recipient through google your issue is not in resolving the mx-record. The Mx record tells an IP-address but doesn't tell about the functionality/behavior of the service behind that ip.

You can resolve the mx-record, so far so good. But you don't need to to resolve the mx on your own as the smtp-client does it on your behalve, just supllying the hostname will do. But note that this was a great excersise to learn more about DNS. No time waste :-)

As far as I recall, sending mail through google in the way you intend you need a google account. Authenticate with the smtp-server with the credentials for that account can open a new perspective

Upvotes: 1

jcwrequests
jcwrequests

Reputation: 1130

It seems you are not alone. Check this out.

:

"Based on my investigation and research, I believe what's happening is your system is connecting directly to the delivery server (aspmx.l.google.com). As this is the delivery server, it does not allow:

  1. Delivery to accounts that are not provisioned on Google (i.e., unauthenticated relaying).

  2. Delivery to multiple different domains within the same SMTP session.

The second one is the one that is important to us. As of the beginning of this month(May2012), adjustments were made to our server settings that mean that our delivery server is strictly enforcing the multiple-domain-not-allowed rule. There are two ways to get around this. The first is to send to separate domains on separate smtp sessions, and the second is to use smtp.gmail.com in place of aspmx.l.google.com."

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

Upvotes: 1

Related Questions