Click here to Skip to main content
15,916,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i need a code for send mail to multiple email address with attachment
Posted

Check this similar thread
send email with attachment[^]
 
Share this answer
 
C#
private void MailSend()
       {
           try
           {
               string mailFrom = "sender_email@yahoo_or_gmail.com";
               string mailTo = "receiver_email@yahoo_or_gmail.com";
               string mailBody = GetHTML();
               string mailSubject = "Sample Email Send::Please click for download file";
               string stmpMailId = "your_stmp_mail@gmail.com";
               string stmpMailPass = "passowrd";

               MailMessage message = new MailMessage();
               SmtpClient smtpClient = new SmtpClient();
               string msg = string.Empty;
               try
               {
                   MailAddress fromAddress = new MailAddress(fromMail);
                   message.From = fromAddress;
                   message.To.Add(toMail);

                   message.Subject = subjectMail;
                   message.IsBodyHtml = true;
                   message.Body = body;
                   smtpClient.Host = "smtp.gmail.com";   // We use gmail as our smtp client
                   smtpClient.Port = 587;
                   smtpClient.EnableSsl = true;
                   smtpClient.UseDefaultCredentials = true;
                   smtpClient.Credentials = new System.Net.NetworkCredential(stmpUserId, stmpPassword);

                   smtpClient.Send(message);
                   msg = "Successful<br>";
               }
               catch (Exception ex)
               {
                   msg = ex.Message;
               }


           }
           catch (Exception ex)
           {

           }
       }
       private string GetHTML()
       {
           string htmlBody = "<html><head><title></title></head><body>This solution is from codeproject.com. I am Md. Humayun Rashed. Please attach your document like this link: "
               +"<a href="http://www.codeproject.com/script/Membership/View.aspx?mid=2948289">Click Me</a></body></html>";

           return htmlBody;
       }</br>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900