我的电子邮件代码有什么问题?

时间:2012-02-14 14:57:16

标签: email smtp gmail sendmail with-statement

这是我的代码:

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") = "myemail@gmail.com"
        .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 = "obroomhall@gmail.com"
        .From = "obroomhall@gmail.com"
        .Subject = "subject"
        .TextBody = "test"
        .Send()
    End With

End Sub

End Class

显然我将myemail和mypassword更改为我需要的内容,但是这不会返回错误代码,也不会发送电子邮件!我做错了什么?

1 个答案:

答案 0 :(得分:1)

smtp.gmail.com使用端口465进行SSL连接。