Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi I need detailed code for how to send an smtp mail with password encryption.
Posted

 
Share this answer
 
Hi dear,

Check this solution.

private void MailSend()
       {
           try
           {
               MailMessage mail = new MailMessage();
               SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
               SmtpServer.Host = "smtp.gmail.com";

               mail.From = new MailAddress("FromMailName@gamil.com");
               mail.To.Add("ToMailName@gmail.com");
               mail.Subject = "Test Mail";
               mail.Body = "This is for testing SMTP mail from GMAIL";

               SmtpServer.Port = 587;

               SmtpServer.Credentials = new System.Net.NetworkCredential("ToMailName@gmail.com", "123456"); // User Mail Name And Mail Password
               SmtpServer.EnableSsl = true;

               SmtpServer.Send(mail);
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.ToString());
           }
       }
 
Share this answer
 
 
Share this answer
 
try {
WebMail.SmtpServer = "smtp.example.com";
WebMail.SmtpPort = 587;
WebMail.EnableSsl = true;
WebMail.UserName = "mySmtpUsername";
WebMail.Password = "mySmtpPassword";
WebMail.From = "rsvps@example.com";
WebMail.Send("party-host@example.com", "RSVP Notification",
Model.Name + " is " + ((Model.WillAttend ?? false) ? "" : "not")
+ "attending");
} catch (Exception) {
@:<b>Sorry - we couldn't send the email to confirm your RSVP.</b>
}
}
 
Share this answer
 
C#
var smtp = new System.Net.Mail.SmtpClient();
   {
       smtp.Host = "smtp.gmail.com";
       smtp.Port = 587;
       smtp.EnableSsl = true;
       smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
       smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
       smtp.Timeout = 20000;
   }
   // Passing values to smtp object
   smtp.Send(fromAddress, toAddress, subject, body);
 
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