[英]Send email from windows app using vb.net
我有以下代碼,我正在嘗試從Windows應用程序發送電子郵件,但無法正常工作……有什么幫助嗎? 請注意,我正在使用vb.net,並且沒有收到任何錯誤。.我只是沒有收到任何電子郵件!
Private Sub senemail()
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress("jocelyne_elkhoury@inmobiles.net")
mail.To.Add("jocelyne_el_khoury@hotmail.co.uk")
'set the content
mail.Subject = "This is an email"
mail.Body = "this is a sample body"
'send the message
Dim smtp As New SmtpClient("127.0.0.1")
smtp.Send(mail)
End Sub
以我的經驗,通過.net(以及之前的vb6)發送電子郵件很奇怪。 有時它應該工作而不能,有時是因為.net錯誤,有時是與smtp服務器不兼容。 這是一些適用於VB 2008的代碼,它應該適用於2010。
Using msg As New MailMessage(New MailAddress(fromAddress, fromName), New MailAddress(toAddress))
Try
Dim mailer As New SmtpClient
msg.BodyEncoding = System.Text.Encoding.Default
msg.Subject = subject
msg.Body = body
msg.IsBodyHtml = False
mailer.Host = mailserver
mailer.Credentials = New System.Net.NetworkCredential(username, password) ' may or may not be necessary, depending on the server
mailer.Send(msg)
Catch ex As Exception
Return ex.Message
End Try
End Using ' mailmsg
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.