如何使用VB.NET通过gmail SMTP服务器发送邮件 [英] How do I send mail through gmail SMTP server using VB.NET

查看:109
本文介绍了如何使用VB.NET通过gmail SMTP服务器发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我发送邮件时,它会显示错误发送邮件失败。

请帮忙!

我也尝试更改端口号但不起作用。

任何人都会得到赞赏,在此先感谢



我的尝试:



Dim client As New SmtpClient()

Dim sendTo As New MailAddress(Trim(txtreceiver.Text))

Dim from As MailAddress =新的MailAddress(修剪(txtUsername.Text))

昏暗的消息As New MailMessage(from,sendTo)

message.IsBodyHtml = True

message .Subject = Trim(txtsubject.Text)

message.Body = Trim(txtrichmsgbody.Text)

'在app.config中使用相同的帐户进行身份验证。

client.Host =smtp.gmail.com

client.EnableSsl = True

Dim basicAuthenticationInfo As New System.Net.NetworkCredential(Trim(txtUsername) .Text),修剪(txtPassword.Text))

client.UseDefaultCredentials = False

client.Credentials = basicAuthenticationInfo

client.Port = 567





尝试

client.Send(消息)

MsgBox(电子邮件发送成功,MsgBoxStyle.Information)

Catch ex As Exception

MsgBox(电子邮件发送失败,MsgBoxStyle.Critical)

结束尝试

解决方案

请尝试添加以下行

 Dim NetworkCred As New NetworkCredential(Trim(txtUsername.Text),Trim(txtPassword.Text))
client.UseDefaultCredentials = True
client.Credentials = NetworkCred
client.Port = 587


kjljkljk

< code>>< a href =>< / a>< / code> 


When i send mail it gives error "Failure sending mail".
Please Help !
I have also tried to change port no but doesn't work.
Any will be Appreciated, Thanks In Advance

What I have tried:

Dim client As New SmtpClient()
Dim sendTo As New MailAddress(Trim(txtreceiver.Text))
Dim from As MailAddress = New MailAddress(Trim(txtUsername.Text))
Dim message As New MailMessage(from, sendTo)
message.IsBodyHtml = True
message.Subject = Trim(txtsubject.Text)
message.Body = Trim(txtrichmsgbody.Text)
' Use the same account in app.config to authenticate.
client.Host = "smtp.gmail.com"
client.EnableSsl = True
Dim basicAuthenticationInfo As New System.Net.NetworkCredential(Trim(txtUsername.Text), Trim(txtPassword.Text))
client.UseDefaultCredentials = False
client.Credentials = basicAuthenticationInfo
client.Port = 567


Try
client.Send(message)
MsgBox("E-mail Send Successfully", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox("E-mail Sending Failed", MsgBoxStyle.Critical)
End Try

解决方案

Please try adding below lines

Dim NetworkCred As New NetworkCredential(Trim(txtUsername.Text),Trim(txtPassword.Text))
client.UseDefaultCredentials = True
client.Credentials = NetworkCred
client.Port = 587


kjljkljk

<code>><a href=""></a></code>


这篇关于如何使用VB.NET通过gmail SMTP服务器发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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