Introduction
In my previous article I explained Send Email Using ASP.Net With C#. In this article I will explain how to send multiple emails with attachments. If you don't bother about the code because I just change some codes in my previous article. ! Let's start.
Code
In my previous article I explained Send Email Using ASP.Net With C#. In this article I will explain how to send multiple emails with attachments. If you don't bother about the code because I just change some codes in my previous article. ! Let's start.
Code
- protected void btn_sendemail_Click(object sender, EventArgs e)
- {
- string to = Txt_toaddress.Text; //To address
- string from = "fromaddress"; //From address
- string[] Multiple = to.Split(',');
- MailMessage message = new MailMessage();
- message.From = new MailAddress(from);
- foreach (string multiple_email in Multiple)
- {
- message.To.Add(new MailAddress(multiple_email));
- }
- if (FileUpload2.HasFile)//Attaching document
- {
- string FileName = Path.GetFileName(FileUpload2.PostedFile.FileName);
- message.Attachments.Add(new Attachment(FileUpload2.PostedFile.InputStream, FileName));
- }
- string mailbody = Txt_Bodycontent.Text;
- message.Subject = Txt_Subject.Text;
- message.Body = mailbody;
- message.BodyEncoding = Encoding.UTF8;
- message.IsBodyHtml = true;
- SmtpClient client = new SmtpClient("smtp.gmail.com", 587); //Gmail smtp
- System.Net.NetworkCredential basicCredential1 = new
- System.Net.NetworkCredential("fromaddress", "fromaddresspassword");
- client.EnableSsl = true;
- client.UseDefaultCredentials = false;
- client.Credentials = basicCredential1;
- try
- {
- client.Send(message);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
We must add the following namespace:
- using System.Net;
- using System.Net.Mail;
- using System.Text;
The following code will help to split the Comma '"," Separated email in the given textbox( Txt_toaddress.Text ).
- string to = Txt_toaddress.Text; //To address
- string from = "fromaddress"; //From address
- string[] Multiple = to.Split(',');
- MailMessage message = new MailMessage();
- message.From = new MailAddress(from);
- foreach (string multiple_email in Multiple)
- {
- message.To.Add(new MailAddress(multiple_email));
- }
If you want to send an attachment with email you can add the following code. Otherwise you just remove this part in the code.
- if (FileUpload2.HasFile)//Attaching document
- {
- string FileName = Path.GetFileName(FileUpload2.PostedFile.FileName);
- message.Attachments.Add(new Attachment(FileUpload2.PostedFile.InputStream, FileName));
- }
If you want to select multiple files in a single file uploader, then you just add AllowMultiple="true". This is one of the option in ASP file upload.
- <div>
- <asp:FileUpload runat="server" ID="FileUpload2" AllowMultiple="true" />
- </div>
Design

Output
Common Error for sending an Email
Check the following reference to solve your 5.5.1 Authentication.
Check the following reference to solve your 5.5.1 Authentication.
Reference: You can also see this in my blog:
Summary
We learned how to send multiple emails with attachment using ASP.NET and C#. I hope this article is useful for all .NET beginners.


Donna PatriaPosted Jun 2, 2025, 4:42 AM EDT
How about with multiple attachment
Gowri SwaminathanPosted Nov 24, 2019, 7:21 PM EST
Useful article
Rajeesh MenothPosted Aug 30, 2016, 12:27 AM EDT
Thank You Delpin Susai Raj
Delpin Susai RajTOP 100Posted Aug 28, 2016, 3:11 AM EDT
Nice
Rajeesh MenothPosted Sep 19, 2015, 10:02 PM EDT
Thank you Saineshwar Bageri
Saineshwar BageriPosted Sep 19, 2015, 9:09 PM EDT
nice one
Rajeesh MenothPosted Sep 18, 2015, 9:42 AM EDT
Thanks Pratham Dave
Pratham DavePosted Sep 17, 2015, 10:32 PM EDT
Nice Article, Good Sharing...
Rajeesh MenothPosted Sep 17, 2015, 9:16 AM EDT
Thanks Santhakumar Munuswamy sir
Santhakumar MunuswamyPosted Sep 17, 2015, 6:17 AM EDT
Thanks for nice article:)
Rajeesh MenothPosted Sep 17, 2015, 2:50 AM EDT
Thanks Sibeesh Venu
Sibeesh VenuTOP 100Posted Sep 17, 2015, 2:26 AM EDT
Nice Share
Rajeesh MenothPosted Sep 17, 2015, 1:09 AM EDT
Thank you Ankit Bansal
Ankit BansalPosted Sep 17, 2015, 12:33 AM EDT
thanks for share..
Rajeesh MenothPosted Sep 16, 2015, 10:33 PM EDT
Thanks Humayun Kabir Mamun
Humayun Kabir MamunPosted Sep 16, 2015, 10:18 PM EDT
Nice...
Rajeesh MenothPosted Sep 16, 2015, 8:31 PM EDT
Thank you Pankaj Kumar Choudhary
Pankaj Kumar ChoudharyTOP 100Posted Sep 16, 2015, 4:36 PM EDT
Thanks for Nice Article Sir.........
Rajeesh MenothPosted Sep 16, 2015, 10:31 AM EDT
Thanks Mohammed Ibrahim
Mohammed IbrahimPosted Sep 16, 2015, 10:29 AM EDT
nice
Shridhar SharmaPosted Sep 16, 2015, 8:59 AM EDT
Nice demo :)
Karthikeyan KPosted Sep 16, 2015, 8:27 AM EDT
Good one bro-:)
Rajeesh MenothPosted Sep 16, 2015, 7:20 AM EDT
Thanks Raja Prs
Raja TPosted Sep 16, 2015, 4:27 AM EDT
Nice one, Thanks for sharing
Muhammad Aqib ShehzadPosted Sep 16, 2015, 4:25 AM EDT
Good Article
Saritha K TPosted Sep 16, 2015, 4:20 AM EDT
Nice
RakeshPosted Sep 16, 2015, 4:14 AM EDT
Nice one buddy
Rajeesh MenothPosted Sep 16, 2015, 3:36 AM EDT
Thanks Kalyankumar Ravichandran
Kalyankumar RavichandranPosted Sep 16, 2015, 2:34 AM EDT
Good one bro!
Prasanth RadhakrishnanPosted Sep 16, 2015, 2:03 AM EDT
NICE ARTICLE Rajeesh Menoth Keep it up :)
Rajeesh MenothPosted Sep 16, 2015, 1:57 AM EDT
Thanks Harshad Pansuriya
Harshad PansuriyaPosted Sep 16, 2015, 1:12 AM EDT
Nice One