如何在 vb.net 中发送 gmail 电子邮件? [英] How do I send a gmail email in vb.net?

查看:13
本文介绍了如何在 vb.net 中发送 gmail 电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发送一封电子邮件,但它给了我一个错误.

I want to send an email, but it gives me an error.

我有这个代码:

Sub sendMail(ByVal title As String, ByVal content As String)
    Dim SmtpServer As New SmtpClient("smtp.gmail.com", 25)
    SmtpServer.Credentials = New Net.NetworkCredential("name@gmail.com", "password")
    Dim mail As New MailMessage("name@gmail.com", "name@gmail.com", title, content)
    SmtpServer.Send(mail)
End Sub

我有一个 try catch 尝试调用此方法,但它不起作用,所以 catch 运行并且我得到了异常:System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was未认证.服务器响应是: 5.7.0 必须首先发出 STARTTLS 命令.b6sm3176487lae.0 - gsmtp 为什么会出现此错误?以及如何解决?

I have a try catch which tries to call this method, it doesnt work so the catch runs and i get thes exception: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. b6sm3176487lae.0 - gsmtp Why do I get this error? and how do I fix it?

推荐答案

Gmail 在端口 465 上使用 SMTP over SSL.

Gmail uses SMTP over SSL on port 465.

尝试做:


  Dim SmtpServer As New SmtpClient("smtp.gmail.com", 465)
  ...
  SmtpServer.EnableSsl = True
  ...

这篇关于如何在 vb.net 中发送 gmail 电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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