會使用寄信的功能主要是用來通知使用者,至於收信的話應該也辦得到不過暫時沒用到就先不研究
要記得是using System.Net.Mail.MailMessage
範例 code
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add("taannmay@gmail.com");
mail.To.Add("toemail@yahoo.com");
mail.From = new MailAddress("frmemail@gmail.com");
mail.Subject = "Email using Gmail";
string Body = "Hi, this mail is to test sending mail" +
"using Gmail in ASP.NET";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential
("myemailID@gmail.com", "mypassword");
//Or your Smtp Email ID and Password
smtp.EnableSsl = true;
smtp.Send(mail);
參考來源: Code Project -Sending email from gmail server wuing asp .net 3.5 with c#
沒有留言:
張貼留言