我正在尝试用VB.NET发送电子邮件。 但是,我认为我没有以正确的方式做到这一点。
我的代码如下:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim sendmail As New Net.Mail.SmtpClient
Dim usertoken As New Object
With sendmail
.Host = "smtp.gmail.com"
.Port = 465
.Credentials = New Net.NetworkCredential("username", "password")
.UseDefaultCredentials = False
End With
sendmail = New Net.Mail.SmtpClient("smtp.gmail.com")
AddHandler sendmail.SendCompleted, AddressOf sendMail_SendCompleted
'sendmail.SendAsync(txtemail.Text, usertoken)
Dim mymsg As System.Net.Mail.MailMessage
mymsg.From = New MailAddress(txtemail.Text)
Dim recipient As MailAddress = New MailAddress(TextBox1.Text)
mymsg.To.Add(recipient)
Catch ex As Exception
End Try
End Sub
关于我应该做什么的任何更正/建议?