CSharp examples for System.Net.Mail:SmtpClient
Send Mail
using System.Web; using System.Text.RegularExpressions; using System.IO;/*from w w w .j av a 2s . com*/ using System.Security.Cryptography; using System.Diagnostics; using System.Collections.Generic; using System; public class Main{ public static void SendMail(string gmailUserName, string gmailPassword, string mailFrom, string mailTo, string commaDelimCCs, string subject, string message, bool isBodyHtml) { try { System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress(gmailUserName, "from yardecart.com"); System.Net.Mail.MailAddress toAddress = new System.Net.Mail.MailAddress(mailTo, "User"); System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(fromAddress, toAddress); msg.IsBodyHtml = isBodyHtml; msg.Subject = subject; msg.Body = message; if (commaDelimCCs != "") msg.CC.Add(commaDelimCCs); System.Net.NetworkCredential cred = new System.Net.NetworkCredential(gmailUserName, gmailPassword); System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 25);//587 r 551 mailClient.EnableSsl = true; mailClient.UseDefaultCredentials = false; mailClient.Credentials = cred; mailClient.Send(msg); } catch (Exception ex) { throw; } } }