如何从Vb.Net向我的Gmail发送电子邮件 [英] How Do I Send A Email From Vb.Net To My Gmail

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

问题描述

Dim SmtpServer As New SmtpClient(smtp.gmail.com,465)

Dim mail As New MailMessage(*********** @ gmail.com ,************* @ gmail,问候,嗨)

SmtpServer.Credentials = New Net.NetworkCredential(***** ******@gmail.com,******)

SmtpServer.Send(邮件)



我试图使用上面的代码但它无法发送邮件。请任何人都可以帮助我。另外,我需要配置smtp服务器吗?请帮我解决我的代码。另外,我是否需要在我的vb表单中添加文本框,或者我应该只有一个按钮来执行整个程序。

解决方案

检查出来:

1. vb.net_send_email [ ^ ]

2. 通过vb.net发送电子邮件 [ ^ ]


Hi

  Dim  SmtpServer 作为  SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Crede ntials = Net.NetworkCredential( yourusername yourpassword
SmtpServer.Port = 587 ' 在这里使用gamil传出TSL端口 - 输入您自己的
SmtpServer.Host = smtp.gmail.com ' 使用gmail作为主机 - 输入您自己的主机
mail = MailMessage ()
mail.From = MailAddress( youremailaddress
mail。 .Add( addresstosendto
mail.Subject = 在此处添加主题
mail.Body = 在此处添加主体
SmtpServer 。发送(邮件)







使用端口号587而不是465







问候

Aravind


试试这个:

  Dim  pweda  As  字符串 =   FromMailPassword 
(ConfigurationManager.AppSettings [password]);
Dim from As String = FromYourmail@gmail.com
' 将其替换为您自己的正确Gmail地址
Dim [ to ] 作为 字符串 = abc@gef.com
' 将其替换为您要向其发送邮件的电子邮件地址
Dim mail As System.Net.Mail.MailMessage()
mail。[ To ] .Add([ to ])
mail.From = MailAddress(from)
mail.Subject = 这是一个测试邮件
mail.SubjectEncoding = System.Text.Encoding.UTF8
mail.Body = 测试邮件。

mail.Priority = MailPriority.High
Dim client 作为 SmtpClient()

' < span class =code-comment>添加Creddentials-使用您自己的电子邮件ID和密码
client.UseDefaultCredentials = False
client.Credentials = System.Net.NetworkCredential(from,pweda)
client.Port = 587
' Gmail适用于此端口
client.Host = < span class =code-string> smtp.gmail.com
client.EnableSsl =
' Gmail适用于服务器安全层
尝试
client.Send(mail)
Response.Write( Message Sent ...
Catch ex As 例外
Dim ex2 As Exception = ex
Dim errorMessage 作为 字符串 = 字符串 .Empty
while ex2 IsNot Nothing
errorMessage + = ex2.ToString()
ex2 = ex2.InnerException
结束
HttpContext.Current.Response.Write(errorMessage)
结束 尝试





谢谢< I> Tadit 的


Dim SmtpServer As New SmtpClient("smtp.gmail.com", 465)
Dim mail As New MailMessage("***********@gmail.com", "*************@gmail", "greetings", "Hi")
SmtpServer.Credentials = New Net.NetworkCredential("***********@gmail.com", "******")
SmtpServer.Send(mail)

I am trying to use the above code but it fails to send mail. Please can anyone help me. Also, do i need to configure the smtp server? Please help me out with my code. Also, do i need to add textboxes in my vb form or should i just have a button to execute the whole program.

解决方案

Check this out:
1. vb.net_send_email[^]
2. send email via vb.net[^]


Hi

Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New Net.NetworkCredential("yourusername", "yourpassword")
            SmtpServer.Port = 587'used gamil outgoing TSL port here - enter your own
            SmtpServer.Host = "smtp.gmail.com"'used gmail as host - enter your own host
            mail = New MailMessage()
            mail.From = New MailAddress("youremailaddress")
            mail.To.Add("addresstosendto")
            mail.Subject = "Add subject here"
            mail.Body = "add body here"
            SmtpServer.Send(mail)




use port no 587 instead of 465



Regards
Aravind


Try this:

Dim pweda As String = "FromMailPassword"
'(ConfigurationManager.AppSettings["password"]);
Dim from As String = "FromYourmail@gmail.com"
'Replace this with your own correct Gmail Address
Dim [to] As String = "abc@gef.com"
'Replace this with the Email Address to whom you want to send the mail
Dim mail As New System.Net.Mail.MailMessage()
mail.[To].Add([to])
mail.From = New MailAddress(from)
mail.Subject = "This is a test mail"
mail.SubjectEncoding = System.Text.Encoding.UTF8
mail.Body = "Test Mail."

mail.Priority = MailPriority.High
Dim client As New SmtpClient()

'Add the Creddentials- use your own email id and password
client.UseDefaultCredentials = False
client.Credentials = New System.Net.NetworkCredential(from, pweda)
client.Port = 587
' Gmail works on this port
client.Host = "smtp.gmail.com"
client.EnableSsl = True
'Gmail works on Server Secured Layer
Try
	client.Send(mail)
	Response.Write("Message Sent...")
Catch ex As Exception
	Dim ex2 As Exception = ex
	Dim errorMessage As String = String.Empty
	While ex2 IsNot Nothing
		errorMessage += ex2.ToString()
		ex2 = ex2.InnerException
	End While
	HttpContext.Current.Response.Write(errorMessage)
End Try



Thanks Tadit


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

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