2012-02-14 59 views
0

這是我的代碼:我的電子郵件代碼有什麼問題?

Public Class form1 

Sub SendMail() 
    Dim iMsg As Object 
    Dim iConf As Object 
    Dim Flds As Object 
    iMsg = CreateObject("CDO.Message") 
    iConf = CreateObject("CDO.Configuration") 
    iConf.Load(-1) ' CDO Source Defaults 
    Flds = iConf.Fields 
    With Flds 
     .Item("http://schemas.Microsoft.Com/cdo/configuration/smtpusessl") = True 
     .Item("http://schemas.Microsoft.Com/cdo/configuration/smtpauthenticate") = 1 
     .Item("http://schemas.Microsoft.Com/cdo/configuration/sendusername") = "[email protected]" 
     .Item("http://schemas.Microsoft.Com/cdo/configuration/sendpassword") = "mypassword" 
     .Item("http://schemas.Microsoft.Com/cdo/configuration/smtpserver") = "smtp.gmail.com" 
     .Item("http://schemas.Microsoft.Com/cdo/configuration/sendusing") = 2 
     .Item("http://schemas.Microsoft.Com/cdo/configuration/smtpserverport") = 25 
     .Update() 
    End With 

    With iMsg 
     .Configuration = iConf 
     .To = "[email protected]" 
     .From = "[email protected]" 
     .Subject = "subject" 
     .TextBody = "test" 
     .Send() 
    End With 

End Sub 

End Class 

很顯然,我改變myemail和輸入mypassword什麼,我需要他們,但是這沒有返回錯誤代碼,也不發電子郵件!我究竟做錯了什麼?

+0

爲什麼要使用古代的CDO而不是使用System.Net.Mail類? – 2012-02-14 15:30:07

+0

我不知道任何其他方式,你可以給我一個例子@JohnSaunders? – user1196604 2012-02-14 15:34:23

+0

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx – 2012-02-14 17:14:39

回答

1

smtp.gmail.com使用端口465進行SSL連接。

+0

爲什麼這會改變什麼?該端口通常是否被計算機阻止? – user1196604 2012-02-14 15:33:36

+0

端口25用於未加密的流量(除非客戶端使用STARTTLS命令) – 2012-02-14 15:37:32