通过vb.net发送邮件时出错 [英] Error in sending mail through vb.net
问题描述
System.Net.Mail.SmtpException:SMTP服务器需要安全连接,或者客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。在System.Net.Mail.SmtpTransport的System.Net.Mail.MailCommand.Send(SmtpConnection conn,Byte []命令,String from)的System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode,String response)上了解更多信息。位于_Default.Button1_Click(对象发件人,EventArgs e)的System.Net.Mail.SmtpClient.Send(MailMessage消息)的.SendMail(MailAddress发件人,MailAddressCollection收件人,String deliveryNotify,SmtpFailedRecipientException& exception)
当我尝试在server.else上发送邮件时,我遇到同样的错误,当我在本地机器上编译并执行相同的代码时,它工作正常。下面是发送消息的代码。
尝试
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server .UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential( gauravgupta1501@gmail.com, *********)
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = False
Smtp_Server.Host = smtp.gmail.com
e_mail = New MailMessage()
e_mail.From = New MailAddress( gauravgupta1501@gmail.com)
e_mail.To.Add( surjiti it@gmail.com)
e_mail.Subject = 查询来自 + txtname.Text
e_mail.IsBodyHtml = False
e_mail.Body = 名称: + txtname.Text + ,电子邮件ID: + txtEmail.Text + ,学院名称: + txtCollegename.Text + ,手机号码: + txtMobile.Text + ,查询: + txtComment.Text
Smtp_Server.Send(e_mail)
Label5.Visible = True
txtCollegename.Text =
txtComment.Text = <跨度class =code-string>
txtEmail.Text =
txtMobile.Text =
txtname.Text =
Catch error_t As Exception
Label5.Visible = True
Label5。 Text = error_t.ToString
结束尝试
错误说明了一切......
Quote:SMTP服务器需要安全连接或客户端未经过身份验证。
您应该
EnableSsl = True
而不是False
,因为 Gmail 适用于SSL
。
执行此操作后,代码应该可以正常工作。否则,请确保用于连接 Gmail 的凭据是正确的。
如需完整的工作代码,请参阅我过去的答案 - 从asp.net发送电子邮件至gmail [< a href =http://www.codeproject.com/Answers/321575/sending-email-to-gmail-from-asp-net#answer3target =_ blanktitle =New Window> ^ ]。
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.Button1_Click(Object sender, EventArgs e)
I am facing the same error when I try to send the mail on server.else when I compile and execute the same code on local machine then it's working fine. below are the code for sending message.
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("gauravgupta1501@gmail.com", "*********")
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = False
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress("gauravgupta1501@gmail.com")
e_mail.To.Add("surjitiit@gmail.com")
e_mail.Subject = "Query From" + txtname.Text
e_mail.IsBodyHtml = False
e_mail.Body = "Name :" + txtname.Text + ", EMail ID :" + txtEmail.Text + ", College Name :" + txtCollegename.Text + ", Mobile Number :" + txtMobile.Text + ", Query :" + txtComment.Text
Smtp_Server.Send(e_mail)
Label5.Visible = True
txtCollegename.Text = ""
txtComment.Text = ""
txtEmail.Text = ""
txtMobile.Text = ""
txtname.Text = ""
Catch error_t As Exception
Label5.Visible = True
Label5.Text = error_t.ToString
End Try
Error says it all...
Quote:The SMTP server requires a secure connection or the client was not authenticated.
You should have
EnableSsl = True
instead ofFalse
, because Gmail works onSSL
.
After doing this, the code should work. Otherwise make sure that credentials, which is used to connect to Gmail are correct.
For a full working code, see my past answer - sending email to gmail from asp.net[^].
这篇关于通过vb.net发送邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!