public static bool Send(string To, string Subject, string Message, string From = "") { using (System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage()) { if (String.IsNullOrEmpty(From)) { message.From = new System.Net.Mail.MailAddress(Models.GlobalSettings.ServiceMail, Models.GlobalSettings.ServiceName); } else { message.From = new System.Net.Mail.MailAddress(From, From); } message.To.Add(To); message.Subject = Subject; message.Body = Message; message.IsBodyHtml = true; message.Priority = System.Net.Mail.MailPriority.Normal; using (System.Net.Mail.SmtpClient mySmtp = new System.Net.Mail.SmtpClient(""mail.abc.com"")) { System.Net.CredentialCache mycache = new System.Net.CredentialCache(); System.Net.NetworkCredential netcare = new System.Net.NetworkCredential(GlobalSettings.SMTPAuthUsername, GlobalSettings.SMTPAuthPassword,"mail.abc.com"); //設定帳號 密碼 與SMTP主機位置 mySmtp.Port = 25; mySmtp.UseDefaultCredentials = false; mySmtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; mySmtp.Credentials = netcare; mySmtp.EnableSsl = false; mySmtp.Send(message); return true; } } }Reference :
http://www.codeproject.com/Tips/301836/Simple-SMTP-E-Mail-Sender-in-Csharp-Console-applic
沒有留言:
張貼留言