Click here to Skip to main content
15,912,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,
I want to send a message to multiple gmail, yahoo and hotmail accounts by using .net.
Can you please help me in this ....

THANKS friends..
Posted

C#
string from ="test@gmail.com"; //Replace this with your own correct Gmail Address

      string to = "test1@gmail.com";//Replace this with the Email Address to whom you want to send the mail

      System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
      mail.To.Add(to);
      mail.From = new MailAddress(from, "One Ghost", System.Text.Encoding.UTF8);
      mail.Subject = "This is a test mail";
      mail.SubjectEncoding = System.Text.Encoding.UTF8;
      mail.Body = "This is Email Body Text";
      mail.BodyEncoding = System.Text.Encoding.UTF8;
      mail.IsBodyHtml = true;
      mail.Priority = MailPriority.High;

      SmtpClient client = new SmtpClient();
      //Add the Creddentials- use your own email id and password

      client.Credentials = new System.Net.NetworkCredential(from, "********");

      client.Port = 587; // Gmail works on this port
      client.Host = "smtp.gmail.com";
      client.EnableSsl = true; //Gmail works on Server Secured Layer
      try
      {
          client.Send(mail);
      }
      catch (Exception ex)
      {
          Exception ex2 = ex;
          string errorMessage = string.Empty;
          while (ex2 != null)
          {
              errorMessage += ex2.ToString();
              ex2 = ex2.InnerException;
          }
          HttpContext.Current.Response.Write(errorMessage);
      } // end try
 
Share this answer
 
v2
Comments
ramuAlla 22-Mar-12 6:23am    
It is working for gmail only ....I want to send message from yahoo and hotmail ....How can I sent?
Mohamed Mitwalli 22-Mar-12 6:38am    
for yahoo change
client.Host ="smtp.mail.yahoo.com";
hotmail
client.Host="smtp.live.com";
 
Share this answer
 
 
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