Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Mail
- {
- private string user = "xxx@gmail.com";
- private string password = "password";
- public void sendEmail(string strTo, string strSubject, string strBody)
- {
- MailMessage objMailMessage = new MailMessage();
- System.Net.NetworkCredential objSMTPUserInfo = new System.Net.NetworkCredential();
- SmtpClient objSmtpClient = new SmtpClient();
- objSmtpClient = new SmtpClient("smtp.web.de", 25);//port 25 or 587
- objSmtpClient.EnableSsl = true;
- objSmtpClient.Timeout = 10000;
- objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
- objSmtpClient.UseDefaultCredentials = false;
- objSmtpClient.Credentials = new System.Net.NetworkCredential(user, password);
- objMailMessage.From = new MailAddress(user);
- objMailMessage.To.Add(new MailAddress(strTo));
- objMailMessage.Subject = strSubject;
- objMailMessage.Body = strBody;
- try
- {
- objSmtpClient.Send(objMailMessage);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- objMailMessage = null;
- objSMTPUserInfo = null;
- objSmtpClient = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement