mark 处理异步发送邮件
全局代码处理
Public Sub SendCompletedCallback(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
' Get the unique identifier for this asynchronous operation.
Dim token As String = CStr(e.UserState)
If e.Cancelled Then
output.show("[" & token & "] Send canceled.")
End If
If e.Error IsNot Nothing Then
output.show("[{" & token & "}] {" & e.Error.ToString() & "}" )
Else
output.show("Message sent.")
End If
End Sub
发送代码
Dim client As New Net.Mail.SmtpClient("smtp.126.com")
'client.Timeout = 60000
client.UseDefaultCredentials = True
client.Credentials = new System.Net.NetworkCredential("lin_hailun@126.com", "6849338.")
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
Dim [from] As New Net.Mail.MailAddress("lin_hailun@126.com", "lin " & ChrW(&HD8) & " hailun", System.Text.Encoding.UTF8)
' Set destinations for the e-mail message.
Dim [To] As New Net.Mail.MailAddress("2450314695@qq.com")
' Specify the message content.
Dim message As New Net.Mail.MailMessage([from], [To])
message.Body = "This is a test e-mail message sent by an application. "
' Include some non-ASCII characters in body and subject.
Dim someArrows As New String(New Char() {ChrW(&H2190), ChrW(&H2191), ChrW(&H2192), ChrW(&H2193)})
message.Body += Environment.NewLine & someArrows
message.BodyEncoding = System.Text.Encoding.UTF8
message.Subject = "test message 1" & someArrows
message.SubjectEncoding = System.Text.Encoding.UTF8
' Set the method that is called back when the send operation ends.
AddHandler client.SendCompleted, AddressOf SendCompletedCallback
Dim userState As String = "test message1"
client.SendAsync(message, userState)