2014-06-19 150 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服務器有一個有效的證書。「 –

相關問題