[英]can't send Email from Webservice written in vb.net
I wanna send an Email from my Webservice, written in vb.net, but I get an Timeout.我想从我的网络服务发送一封电子邮件,用 vb.net 编写,但我收到了超时。 What is wrong?
怎么了?
Dim toaddress As MailAddress = New MailAddress("xxx")
Dim fromaddress As MailAddress = New MailAddress("yyy")
' The structure for MailMessage(from, to)
Dim message As MailMessage = New MailMessage(fromaddress, toaddress)
message.Subject = "I have sent you a message from a program!"
message.Body = "Hello World!"
Dim messanger As SmtpClient = New SmtpClient("smtpxxx", 995)
messanger.Credentials = New NetworkCredential("user", "password")
messanger.EnableSsl = True
messanger.Send(message)
You are doing many things wrong and some of the information you have given are not clear enough.你做错了很多事情,你提供的一些信息不够清楚。 host name and port names have to give properly.
主机名和端口名必须正确给出。 it chooses which mail service you are using, from your code it is not correctly provided, so i will give a snippet that uses gmail to send mail.
它选择您正在使用的邮件服务,从您的代码中它没有正确提供,所以我将给出一个使用 gmail 发送邮件的片段。 please go through this and make changes as per your
SmtpHost
.请完成此操作并根据您的
SmtpHost
进行更改。
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("email", "password")
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(txtemail.Text)
e_mail.To.Add(txtemail.Text)
e_mail.Subject = "Email Sending"
e_mail.IsBodyHtml = False
e_mail.Body = txtMessage.Text
Smtp_Server.Send(e_mail)
MsgBox("Mail Sent")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
This link help you to find the smtp.Server and Port numbers , you can use this thread for check the limitations of smtp.servers此链接可帮助您找到smtp.Server 和端口号,您可以使用此线程检查 smtp.servers 的限制
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.