Loading content, please wait..
首頁 > 網站製作文章 > ASP.NET GMAIL發信 C#

網站製作文章

ASP.NET GMAIL發信 C#

C#
private void button1_Click(object sender, EventArgs e)
{
    MailMessage mail = new MailMessage();
    NetworkCredential cred = new NetworkCredential("xxx@gmail.com", "password");
    //收件者
    mail.To.Add("ggyy@hotmail.com,ooxx@hotmail.com");
    mail.Subject = "subject";
    //寄件者
    mail.From = new System.Net.Mail.MailAddress("xxx@gmail.com");
    mail.IsBodyHtml = true;
    mail.Body = "message";
    //設定SMTP
    SmtpClient smtp = new SmtpClient("smtp.gmail.com");
    smtp.UseDefaultCredentials = false;
    smtp.EnableSsl = true;
    smtp.Credentials = cred;
    smtp.Port = 587;
    //送出Mail
    smtp.Send(mail);
}
VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim mail As New MailMessage()
    Dim cred As New NetworkCredential("xxx@gmail.com", "password")
    '收件者
    mail.[To].Add("ggyy@hotmail.com,ooxx@hotmail.com")
    mail.Subject = "subject"
    '寄件者
    mail.From = New System.Net.Mail.MailAddress("xxxu@gmail.com")
    mail.IsBodyHtml = True
    mail.Body = "message"
    '設定SMTP
    Dim smtp As New SmtpClient("smtp.gmail.com")
    smtp.UseDefaultCredentials = False
    smtp.EnableSsl = True
    smtp.Credentials = cred
    smtp.Port = 587
    '送出Mail
    smtp.Send(mail)
End Sub



來源http://www.dotblogs.com.tw/yc421206/archive/2010/01/05/12803.aspx

關鍵字:ASP.NET GMAIL發信 C# , 網站製作文章 , 網站設計-台北網站設計公司,