使用vb.net 2008发送电子邮件

Send Email using vb.net 2008

本问题已经有最佳答案,请猛点这里访问。

Possible Duplicate:
Sending email in .NET through Gmail

我想使用vb.net2008和gmail帐户发送电子邮件。有人能帮我写代码吗?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Dim Msg As New MailMessage

Dim myCredentials As New System.Net.NetworkCredential
myCredentials.UserName =" [email protected]"
myCredentials.Password ="Password"

Msg.IsBodyHtml = False

Dim mySmtpsvr As New SmtpClient()
mySmtpsvr.Host ="smtp.web.de"
mySmtpsvr.Port = 25

mySmtpsvr.UseDefaultCredentials = False
mySmtpsvr.Credentials = myCredentials

Try
  Msg.From = New MailAddress("[email protected]")
  Msg.To.Add("entchen@empf?nger.de")
  Msg.Subject ="Betreff"
  Msg.Body ="Inhalt"
  mySmtpsvr.Send(Msg)
  MsgBox("E-Mail gesendet.", MsgBoxStyle.Information, Title:="Information")
Catch ex As Exception
  MsgBox (Err.Number & ex.Message & ex.StackTrace.ToString) 'Falls ein Fehler auftritt wird eine MsgBox angezeigt
End Try

希望有帮助……