Send email via vb.net web application

左心房为你撑大大i 提交于 2019-12-24 02:55:10

问题


I'm trying to send a simple plain-text email through my VB.net web application.

I've followed the instructions here: http://www.systemnetmail.com/faq/3.1.1.aspx

But, regardless of what email addresses I use, I keep getting the message "unable to connect to the remote server".

Here is my code

'Create the mail message
Dim mail As New MailMessage()

'set the addresses
mail.From = New MailAddress("<email1>")
mail.To.Add("<email2>")

'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)

Why is this not working?


回答1:


Are you sure that your pc (127.0.0.1, loopback ip) is a SMTP server?
Dim smtp As New SmtpClient(host) means that your pc tries to connect to smtp server host and use it to send an email.
Check that and you gonna solve your problem...
Just to try: change 127.0.0.1 with the default SMTP server you use in your email software and see what happens...
More: catch the exception (if one is raised) and take note of the message...




回答2:


Try to add this

smtp.Credentials = CredentialCache.DefaultNetworkCredentials;

and review your firewall settings, maybe the port is closed.



来源:https://stackoverflow.com/questions/6865789/send-email-via-vb-net-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!