2016-03-04 77 views
-4

我正在学习我的学期项目,这是一个电子商务应用程序的Windows版本。我想发送电子邮件给我的用户关于注册,销售和进一步更新。我将如何通过我的vb.net应用程序发送电子邮件?

+0

这不是对于这个网站来说是一个合适的问题,并且可能因为太宽泛而被搁置。如果你能向我们展示你已经尝试了什么,以及你有什么困难,那么有人将能够提供帮助。只有涉及合理的努力的问题才会在这里得到最好的帮助。 – halfer

回答

0

谷歌搜索10S为您提供了10K答案..

发送邮件与.NET最简单的方法是使用System.Net.Mail命名空间和一个SMTP服务器,你有一个电子邮件帐户一样mostlikely的Gmail。

Imports System.Net.Mail 

Module Module1 

Sub Main() 

    Try 

     Dim SmtpServer As New SmtpClient() 
     Dim mail As New MailMessage() 
     SmtpServer.UseDefaultCredentials = False 
     SmtpServer.Credentials = New Net.NetworkCredential("[email protected]", "yourpassword") 
     SmtpServer.EnableSsl = True 
     SmtpServer.Port = 465 
     SmtpServer.Host = "smtp.gmail.com" 
     SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network 

     mail = New MailMessage 
     mail.From = New MailAddress("[email protected]") 
     mail.To.Add("[email protected]") 
     mail.Subject = "This is the subject" 
     mail.Body = "This is the body" 

     SmtpServer.Send(mail) 

    Catch ex As Exception 

     MsgBox(Err.Number & vbNewLine & ex.Message) 

    End Try 

End Sub 

End Module 

提示,如果这不起作用:

  • 检查您的网络凭据手动

  • 凝视你的反病毒事件日志,因为如果你使用McAfee的System.Net.Mail会被你自己的保护作为垃圾邮件拦截。

  • 使用CDOSYS方法来发送邮件

  • 使用Microsoft.Office.Interop.Outlook方法来发送邮件

  • 使用Telnet与SMTP服务器来测试你的沟通

相关问题