hello,
How to send multiple attachment in email in asp.net. I am already attaching pdf as attachment, but i want to attach one more pdf along with that.
Let me know if anything can be done.
Thanks in advance !
hello,
How to send multiple attachment in email in asp.net. I am already attaching pdf as attachment, but i want to attach one more pdf along with that.
Let me know if anything can be done.
Thanks in advance !
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jithu ThomasRank #437 · 5.7K reputationPosted Feb 2, 2024, 10:32 AM EST
using System.Net; using System.Net.Mail; using System.Net.Mime; // Create a MailMessage object MailMessage mail = new MailMessage(); // Set the sender, recipient, subject, and body mail.From = new MailAddress("[email protected]"); mail.To.Add("[email protected]"); mail.Subject = "Your Subject"; mail.Body = "Your email body"; // Attach the first PDF Attachment attachment1 = new Attachment("path_to_first_pdf.pdf", MediaTypeNames.Application.Pdf); mail.Attachments.Add(attachment1); // Attach the second PDF Attachment attachment2 = new Attachment("path_to_second_pdf.pdf", MediaTypeNames.Application.Pdf); mail.Attachments.Add(attachment2); // Set up the SMTP client and send the email SmtpClient smtpClient = new SmtpClient("your_smtp_server"); smtpClient.Credentials = new NetworkCredential("your_username", "your_password"); smtpClient.Send(mail);Tuhin PaulRank #7 · 71.9K reputationPosted Feb 3, 2024, 4:02 AM EST
using System; using System.Net.Mail; using System.Net.Mime; using System.IO; namespace EmailAttachmentExample { class Program { static void Main() { // Sender's email address and password string senderEmail = "[email protected]"; string senderPassword = "your-email-password"; // Recipient's email address string recipientEmail = "[email protected]"; // Create a new MailMessage MailMessage mail = new MailMessage(); // Set the sender and recipient addresses mail.From = new MailAddress(senderEmail); mail.To.Add(recipientEmail); // Set the subject and body of the email mail.Subject = "Multiple Attachments Example"; mail.Body = "Please find attached multiple PDF files."; // Attach the first PDF file string pdfFilePath1 = @"C:\path\to\your\first\file.pdf"; Attachment attachment1 = new Attachment(pdfFilePath1, MediaTypeNames.Application.Pdf); mail.Attachments.Add(attachment1); // Attach the second PDF file string pdfFilePath2 = @"C:\path\to\your\second\file.pdf"; Attachment attachment2 = new Attachment(pdfFilePath2, MediaTypeNames.Application.Pdf); mail.Attachments.Add(attachment2); // Create and configure the SMTP client SmtpClient smtpClient = new SmtpClient("smtp.your-email-provider.com"); smtpClient.Port = 587; smtpClient.Credentials = new System.Net.NetworkCredential(senderEmail, senderPassword); smtpClient.EnableSsl = true; try { // Send the email smtpClient.Send(mail); Console.WriteLine("Email sent successfully!"); } catch (Exception ex) { Console.WriteLine($"Error sending email: {ex.Message}"); } finally { // Dispose of attachments and MailMessage attachment1.Dispose(); attachment2.Dispose(); mail.Dispose(); } } } }You can send multiple attachments in an email in ASP.NET by adding multiple
Attachmentobjects to theMailMessageinstance. Here's an example of how you can modify your code to attach multiple PDF files to an emailRajeesh MenothRank #118 · 18.4K reputationPosted Feb 5, 2024, 1:45 AM EST
Hi,
I have published article for the same and you can refer:
https://www.c-sharpcorner.com/UploadFile/2a6dc5/send-multiple-email-with-attachment-using-Asp-Net-with-C-Sharp/