从vb.net 2010发送电子邮件时出错 [英] error while sending email from vb.net 2010
问题描述
Imports System.Net
Imports System.Net.Mail
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblDateTime.Text = "Date: " & Date.Today() & " " & "Time: " & TimeOfDay()
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Try
Dim email As New MailMessage()
Dim smtp As New SmtpClient()
smtp.UseDefaultCredentials = False
smtp.Credentials = New Net.NetworkCredential(txtUsername.Text, txtPassword.Text)
smtp.Port = 465
smtp.EnableSsl = True
smtp.Host = "smtp.gmail.com"
email = New MailMessage()
email.From = New MailAddress(txtUsername.Text)
email.To.Add(txtTo.Text)
email.Subject = txtSubject.Text
email.IsBodyHtml = False
email.Body = richTxtBody.Text
email.Priority = MailPriority.High
smtp.Send(email)
MsgBox("Message Sent Successfully.", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
End Class
请帮我解决错误...我使用gmail smtp服务器587的端口,但应用程序给出了异常smtp服务器没有响应。所以我用谷歌搜索并发现gmail新的smtp端口为465我用过。现在,如果我点击发送按钮,应用程序会延迟一段时间,最后会出现错误操作已经超时...请问代码有什么问题,我的意思是我做错了什么。或者我是否必须配置我的Gmail帐户以允许我将其用作smtp的网关? 。
Please help me with the error... I used the port for the gmail smtp server 587 but the application gave an exception "smtp server not responding". so i googled and discovered gmail new smtp port to be 465 which i used. Now if i click the send button, the application delays for some minute and finally gives the error "the operation has timed out" ... please what is the problem with the code, i mean what am i doing wrong. or do i have to configure my gmail account to allow me use it as a gateway for smtp? .
推荐答案
您将无法使用Google电子邮件服务器发送电子邮件。
我认为不可能 - 如果是是的,我相信会收取费用。
You will not be able to send email using the Google email server.
I dont think it is possible - and if it is, I'm sure it will be charged.
这篇关于从vb.net 2010发送电子邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!