這是我的代碼:我的電子郵件代碼有什麼問題?
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什麼,我需要他們,但是這沒有返回錯誤代碼,也不發電子郵件!我究竟做錯了什麼?
爲什麼要使用古代的CDO而不是使用System.Net.Mail類? – 2012-02-14 15:30:07
我不知道任何其他方式,你可以給我一個例子@JohnSaunders? – user1196604 2012-02-14 15:34:23
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx – 2012-02-14 17:14:39