2014-06-19 118 views
-1

我已经使用此代码发送电子邮件。当我测试在LOCALHOST这个代码,它工作正常,但在主机上,我得到这个错误:电子邮件不发送使用主机上的Gmail smtp

Failure sending mail.few

我的代码是:

Dim MailMsg As New MailMessage(New Net.Mail.MailAddress("[email protected]"), New Net.Mail.MailAddress("[email protected]")) 
MailMsg.Subject = "test" 
MailMsg.Body = "test" 
MailMsg.IsBodyHtml = True 
Dim SmtpMail As New Net.Mail.SmtpClient 
Dim SMTPUserInfo As New Net.NetworkCredential() 
SMTPUserInfo.UserName = "MYUSERNAME" 
SMTPUserInfo.Password = "MYPASSWORD" 
SmtpMail.UseDefaultCredentials = False 
SmtpMail.Credentials = SMTPUserInfo 
SmtpMail.Host = "smtp.gmail.com" 
SmtpMail.Port = 587 
SmtpMail.EnableSsl = True 
SmtpMail.Send(MailMsg) 
+0

也许Gmail会阻止你..通过其他检查服务器 – Itiel

+0

我已经使用了2个Gmail帐户,但问题仍然存在 – Mohammad

+0

端口是否打开? – WozzeC

回答

0
'Start by creating a mail message object 
    Dim MyMailMessage As New MailMessage() 

    'From requires an instance of the MailAddress type 
    MyMailMessage.From = New MailAddress("[email protected]") 

    'To is a collection of types 
    MyMailMessage.To.Add("[email protected]") 

    MyMailMessage.Subject = "XXXXXXX" & x 
    MyMailMessage.Body = "XXXXXXXXXXXXXXXXXXX " 

    Dim attach As New Attachment(fileName) 

    MyMailMessage.Attachments.Add(attach) 

    'Create the SMTPClient object and specify the SMTP GMail server 
    Dim SMTPServer As New SmtpClient("smtp.gmail.com") 
    SMTPServer.Port = 587 
    SMTPServer.Credentials = New System.Net.NetworkCredential("[email protected]", "PASSWD") 
    SMTPServer.EnableSsl = True 
    SMTPServer.Send(MyMailMessage) 

    SMTPServer.Dispose() 

    MyMailMessage.Dispose() 
+0

这就是我正在做的,但我得到“根据验证过程,远程证书无效”当SMPT服务器有一个有效的证书。“ –

相关问题