Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with WebMail.Send when it comes to multiple recipients?

We've seen a few similar questions on StackOverflow before regarding System.Web.Helpers.Webmail.Send but I see no proper explanation for what's going on.

Regarding the to: parameter, the documentation says:

The email address of the recipient or recipients. Separate multiple recipients using a semicolon (;).

and I've seen answers saying "use a comma because the docs are wrong", or "use a semicolon", or "maybe it's an environment issue".

The code

WebMail.Send(
    to: "[email protected],[email protected]",
    from: "[email protected]",
    subject: "Some Automated Email",
    body: "<strong>Lorem Ipsum</strong>",
    isBodyHtml: true
);

I've tried a few scenarios:

[email protected];[email protected]

No emails recieved: An invalid character was found in the mail header: ';'.

[email protected]; [email protected]

Only the first recipient receives the email

[email protected],[email protected]

both recieved the email

[email protected], [email protected]

both recieved the email

[email protected], [email protected]

First recieved the email, but uncaught exception: Mailbox unavailable. The server response was: 5.7.1 Unable to relay

[email protected], [email protected]

No emails recieved: An invalid character was found in the mail header: ','.

Can anybody shed some light on this? I've actually had even more bizzare behaviour on a different server; I'm using Exchange for the above tests, but actually experienced different behaviour on hMailServer where [email protected],[email protected] resulted in a silent failure with no server errors and no outgoing mail in hMailServer logs. On the system with hMailServer I have only had success with a single address.

like image 804
Zac Avatar asked Aug 29 '13 16:08

Zac


People also ask

How do I send an email to multiple recipients in webmail?

You can send a mass email to more than one recipient using the BCC feature. Click the compose box, after composing your message, click on BCC and add all your recipients. This will send the emails to the recipients keeping email addresses hidden from each other.

How do I send email to multiple users individually?

Open a new email and write the message you intend to send to your contact list. Click BCC in the top-right of your Compose window. Add all the email addresses to which you intend to send the message. It might help to copy and paste your list into this field.

When sending an email to multiple recipients separate the addresses with a?

In the 'To' address box, type in the first recipient's email address. Then type a comma and a space, to separate this address from the next email address. Type in the second address and continue, inserting a comma and a space between each subsequent address.

How would you ensure a delivery is not sent to multiple recipients with the same email address?

Bcc, or “blind carbon copy” functions the same as “Cc”, with one difference: Bcc-ed addresses are hidden from all recipients. Both features are available in Gmail and Outlook. To send the same email separately to various users in Outlook follow the guide below. Find and add the Bcc field for your message.


1 Answers

This probably has to do with the variety of relays you are connecting to, and the variety of methods they accept. Not only do the delimiter characters matter to each specific mail server, but the e-mail addresses also do (since different relays will be configure to accept certain e-mails, and will throw a variety of error codes back for bad e-mails, which will in turn throw a variety of exceptions).

The System.Net.Mail namespace has a MailMessage object that contains MailAddressCollection objects for To, CC, and Bcc that you can just call Add() on for each recipient.

I have a library that sends mail (without a relay) that uses it (everything goes to Bcc), you can check the code out there. If you happen to use the library, be sure to keep your IP address in good reputation and make sure your DNS records are all setup the same way you would if you were a relay (PTR and A records all setup).

like image 195
Thabo Avatar answered Oct 22 '22 13:10

Thabo