tls を使用して電子メールを送信する必要があります。vb.net で送信するにはどうすればよいですか? サーバーの手動入力が必要なため、サンダーバードで確認したサーバー情報は次のとおりです。1.smtpサーバー:pod51004.outlook.com 2.ポート:587 3.TLSSTARTは、私が覚えている接続セキュリティです
このシナリオでは live@edu メール サービスを使用しています。私の試みたコードは次のとおりです。
Class Mailer
''one static method for sending e-mails
Shared Sub SendMail(ByVal [From] As String, ByVal [To] As String, _
ByVal Subject As String, ByVal Body As String, ByVal MailServer _
As String, Optional ByVal IsBodyHtml As Boolean = True, _
Optional ByVal MailPort As Integer = 25, _
Optional ByVal Attachments() As String = Nothing, Optional _
ByVal AuthUsername As String = Nothing, Optional ByVal _
AuthPassword As String = Nothing)
'On Error GoTo ErrorHandler
'create a SmtpClient object to allow applications to send
'e-mail by using the Simple Mail Transfer Protocol (SMTP).
Dim MailClient As SmtpClient = New SmtpClient(MailServer, MailPort)
MailClient.EnableSsl = True
MailClient.DeliveryMethod = SmtpDeliveryMethod.Network
'MailClient.UseDefaultCredentials = False
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
Dim nc As NetworkCredential = New NetworkCredential(AuthUsername, AuthPassword)
''create a MailMessage object to represent an e-mail message
''that can be sent using the SmtpClient class
Dim MailMessage = New MailMessage( _
[From], [To], Subject, Body)
''sets a value indicating whether the mail message body is in Html.
MailMessage.IsBodyHtml = IsBodyHtml
''sets the credentials used to authenticate the sender
If (AuthUsername IsNot Nothing) AndAlso (AuthPassword _
IsNot Nothing) Then
MailClient.Credentials = nc
End If
Dim
''add the files as the attachments for the mailmessage object
If (Attachments IsNot Nothing) Then
For Each FileName In Attachments
MailMessage.Attachments.Add( _
New Attachment(FileName))
Next
End If
MailClient.Send(MailMessage)
''ErrorHandler:
'' MsgBox("My error")
End Sub
End Class
アイデアが欲しい人はいますか?