0

I have developed a asp.net Mvc 4 project and now i am planing to integrate a Mail system in my application.Initially i taught like integrating mail System in my existing web application but later i moved it to a console application using Scheduler to send mail at some time interval.

My scenario is like i have a list of mail ids and i need to send mail to all these mail ids . I have checked System.Web.Mail and i found i can only give one email address at a time. Is it possible in System.Web.Mail or is there any other library available to achieve my scenario.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Cyber
  • 4,844
  • 8
  • 41
  • 61
  • possible duplicate of [Unable to send an email to multiple addresses/recipients using C#](http://stackoverflow.com/questions/3209129/unable-to-send-an-email-to-multiple-addresses-recipients-using-c-sharp) – abatishchev Feb 27 '14 at 05:46

3 Answers3

4

To in System.Net.Mail is a MailAddressCollection,so you can add how many addresses you need.

MailMessage msg = new MailMessage();
msg.To.Add(...);
msg.To.Add(...);
Cris
  • 12,799
  • 5
  • 35
  • 50
0

Chris's answer is correct but you may want to also consider using a mail service. Here are some you could try - they all have a free tier to get started on.

Community
  • 1
  • 1
Geoff Appleford
  • 18,538
  • 4
  • 62
  • 85
  • I second this suggestion. In the first mail system I ever incorporated into an application, I used a local SMTP server. This resulted in some deliverability issues, mostly false-positive spam flagging. Let some other service do the job, you just send them the email addresses and the content. Amazon SES is a dirt cheap option that more or less functions like a 3rd party SMTP server, so there is almost no integration work to be done... quick and easy. – Gadget27 Feb 27 '14 at 06:28
  • @Gadget27 - Thanks, I've added a link to Amazon SES – Geoff Appleford Feb 27 '14 at 07:18
0

You can easily sent emails to more than one recipient. Here is a sample that uses a SMTP server to send an email to multiple addreses:

//using System.Net.Mail;

public void SendEmail(){

    MailMessage email = new MailMessage();

    email.To.Add("first@email.com");
    email.To.Add("second@email.com");
    email.To.Add("third@email.com");

    email.From = new MailAddress("me@email.com");

    string smtpHost = "your.SMTP.host";
    int smtpPort = 25;

    using(SmtpClient mailClient = new SmtpClient(smtpHost, smtpPort)){
        mailClient.Send(email);
    }
}

Just a note: if you go with SMTP, you should probably have a look also on MSDN for the SmtpClient.Send method, just to be sure you are catching any related exceptions.

Lucian
  • 3,981
  • 5
  • 30
  • 34