[asp.net]用gmail发信(寄,smtp,mail,email,信,gmail)

摘要:[asp.net]用gmail发信(寄,smtp,mail,email,信,gmail)



Dim objMail As New System.Net.Mail.MailMessage
Dim id As String = "[email protected]"
Dim passwd As String = "yourPassword"
Try
	With objMail
		.Body = "测试的body"""
		.Subject = "测试主题"                
		.From = New System.Net.Mail.MailAddress("[email protected]", "大帅哥")
		.IsBodyHtml = True
		.To.Add(New System.Net.Mail.MailAddress("[email protected]", "另一个大帅哥"))
	End With
	Dim smtpMail As New System.Net.Mail.SmtpClient()
	smtpMail.Host = "smtp.gmail.com"
	smtpMail.Port = 25
	'smtpMail.Port = 587 企业的防火墙通常会挡住这种奇怪的port
	smtpMail.EnableSsl = True
	smtpMail.UseDefaultCredentials = False
	smtpMail.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network            
	smtpMail.Credentials = New System.Net.NetworkCredential(id, passwd)

	'smtpMail.SendAsync(objMail, "test")
	smtpMail.Send(objMail)
	MsgBox("mail success!!")

Catch ex As Exception
	MsgBox(ex.ToString)
End Try