如何使用VB.net在Gmail中进行自动化 [英] How to doing automailing in Gmail using VB.net
问题描述
嗨朋友们,
我在使用g-mail向特定的人发送电子邮件时遇到问题。实际上我的项目是从一个位置复制一个excel文件并发送给特定的人。文件已成功复制,但无法发送电子邮件。将出现一个消息框,显示; System.Net.Mail.SmtpException:SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.7.0必须首先发出STARTTLS命令.qh5sm9940329pbb .71 - gsmtp
我使用的代码是:
Hi friends,
Here I have problem when send a email to a specific person using g-mail. Actually my project is copy a excel file from a location and send to a specific person. The file is successfully copy, but the email is cannot be send. a message box is appear, which is show "quot;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. qh5sm9940329pbb.71 - gsmtp""
the code were I used is:
Sub Main()
CopyFile = "\\192.168.5.1\fbar\TOOLS\ProbingApps\ProbingSystem\testMail.xlsx"
MyHour = Format(Now, "hh")
MyMinutes = Format(Now, "mm")
MySec = Format(Now, "ss")
MyDate = Format(Now, "dd")
MyMonth = Format(Now, "MM")
myYear = Format(Now, "yyyy")
Mydirectory = "C:\Users\Thaneskumar\Desktop\test2\"
MyExtension = ".xlsx"
MyFileName = Mydirectory + MyHour + MyMinutes + MySec + "_" + MyDate + MyMonth + "_" + myYear + MyExtension
CopyTo = MyFileName
If System.IO.File.Exists(CopyFile) = True Then
System.IO.File.Copy(CopyFile, CopyTo)
MsgBox("File Copied")
End If
automail()
MsgBox("Mail send")
End Sub
Public Sub automail()
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("cgthanes44@gmail.com", "******")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("cgthanes44@gmail.com")
mail.To.Add("cgthanes33@yahoo.com")
mail.Subject = "Test Mail"
Dim attach As New Attachment(MyFileName)
mail.Attachments.Add(attach)
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
任何人都可以帮助我....
谢谢。
此致,
Thanes
Can anyone help me....
Thanks.
Regards,
Thanes
推荐答案
首先确保凭证正确。
然后参考我过去的答案 - 发送电子邮件至来自asp.net的gmail [ ^ ]。你会找到一个完整的工作代码。
查看代码,我看到缺少以下几行。
First of all make sure that the credentials are correct.
Then refer my past answer - sending email to gmail from asp.net[^]. You will find a complete working code.
Looking at the code, I see that the following lines are missing.
client.UseDefaultCredentials = false;
client.EnableSsl = true; //Gmail works on Server Secured Layer
>
这篇关于如何使用VB.net在Gmail中进行自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!