VB.net でメールを送信する
VB.net でメールを送信するためのコード。
1. メール送信用のメソッドを作成
Private Sub MailSending(ByVal adr, sbj, bdy As String)
Dim msg As New System.Net.Mail.MailMessage("***@example.com", adr, sbj, bdy)
Dim sc As New System.Net.Mail.SmtpClient()
sc.Host = "smtp.example.com"
sc.Port = 587
sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
sc.Credentials = New System.Net.NetworkCredential("***@example.com", "********")
sc.Send(msg)
msg.Dispose()
sc.Dispose()
End Sub
2. 呼び出す
Call MailSending("宛先", "件名", "本文")
Very cool
返信削除