使用VB.NET发送电子邮件

时间:2015-03-03 06:03:11

标签: vb.net

我正在尝试用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

关于我应该做什么的任何更正/建议?

0 个答案:

没有答案