MailAddress from = new MailAddress("寄件者郵件地址", "寄件者顯示的名稱", System.Text.Encoding.UTF8); MailAddress to = new MailAddress("收件者郵件地址"); MailMessage message = new MailMessage(from , to ); message.IsBodyHtml = true; message.BodyEncoding = System.Text.Encoding.UTF8; //E-mail編碼 message.Subject = "主旨"; message.Body = body; //E-mail內容 SmtpClient smtpClient = new SmtpClient("郵件伺服器", prot); smtpClient.Credentials = new System.Net.NetworkCredential("帳號", "密碼"); //若不需要帳號密碼的可省略,是否可省略要看Mail Server設定是否一定要驗證 smtpClient.Send(message);
提醒:記得要加上using System.Net.Mail;
沒有留言:
張貼留言