如何使用Vb.Net向我的Gmail地址发送电子邮件 [英] How Do I Send An Email To My Gmail Address Using Vb.Net

查看:113
本文介绍了如何使用Vb.Net向我的Gmail地址发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了以下代码,但它显示system.net.mail无法发送电子邮件。它还显示连接主机无法响应。那么,请有人告诉我这是什么问题。我正在使用我学校的局域网连接,我没有配置任何电子邮件客户端。我也尝试过改变端口,但它仍然无效。

I used the following code but it shows that the system.net.mail failed sending email . It also shows that the connection host failed to respond. So, please can anyone tell me what is the problem. I am using LAN connection of my school and i haven't configured any email client. I have also tried changing ports but it still doesnot work.

Try
  Dim Smtp_Server As New SmtpClient
  Dim e_mail As New MailMessage()
  Smtp_Server.UseDefaultCredentials = False
  Smtp_Server.Credentials = New Net.NetworkCredential("username@gmail.com", "password")
  Smtp_Server.Port = 587
  Smtp_Server.EnableSsl = True
  Smtp_Server.Host = "smtp.gmail.com"

  e_mail = New MailMessage()
  e_mail.From = New MailAddress(txtFrom.Text)
  e_mail.To.Add(txtTo.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

推荐答案

您好,原因很可能是因为您没有使用gmail启用SSL。我建议您添加:



Hi, the cause is most probably because you did not enable the SSL with gmail. I suggest that you add:

Try
  Dim Smtp_Server As New SmtpClient
  Dim e_mail As New MailMessage()
  Smtp_Server.UseDefaultCredentials = False
  Smtp_Server.Credentials = New Net.NetworkCredential("username@gmail.com", "password")
  Smtp_Server.Port = 587
  Smtp_Server.EnableSsl = True
  Smtp_Server.Host = "smtp.gmail.com"
  SmtpServer.EnableSsl = True





SmtpServer.EnableSsl =您的代码为True。此外,Gmails通过这种方式发送电子邮件时有时会出现问题,因此在您测试解决方案后,请登录您的Gmail并检查安全问题(他们很可能会询问您有关该交易的信息,您可能需要在登录时输入验证码页面以验证您是使用它的人)。另外,检查Gmail中是否启用了SMTP。



另外请检查如何通过VB.NET或C#从您的GMAIL账户发送邮件。 Windows编程,带有一点自定义 [ ^ ]教程。


这篇关于如何使用Vb.Net向我的Gmail地址发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆