Cyber
Cyber

Reputation: 5020

How to send mails to multiple reciepients from web application?

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.

Upvotes: 0

Views: 233

Answers (3)

Lucian
Lucian

Reputation: 4001

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("[email protected]");
    email.To.Add("[email protected]");
    email.To.Add("[email protected]");

    email.From = new MailAddress("[email protected]");

    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.

Upvotes: 0

Geoff Appleford
Geoff Appleford

Reputation: 18832

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.

Upvotes: 0

Cris
Cris

Reputation: 13351

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(...);

Upvotes: 4

Related Questions