繁体   English   中英

使用vb.net从Windows应用发送电子邮件

[英]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
  1. 如果这不起作用,请尝试对邮件服务器使用localhost而不是127.0.0.1。
  2. 如果这样不起作用,请尝试使用邮件服务器的系统名称(网络上显示的名称)。
  3. 如果这不起作用,请尝试使用具有您自己的用户名和密码的外部smtp服务器(仅用于测试)。
  4. 利润。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM