发布网友 发布时间:2022-05-03 00:52
共3个回答
热心网友 时间:2022-06-28 19:44
出错的原因是:
Const Email_From = "邮箱" 应改为具体的邮箱:如:12345678@qq.com
Const Email_To = "收件邮箱" 应改为具体的邮箱:如:12345678@qq.com
修改后的代码:
Private Sub Command1_Click()
Dim CDO As Object
Const Email_From = "123@qq.com" '请修改
Const Password = "123456"'请修改
Const Email_To = "123@qq.com"'请修改
Set CDO = CreateObject("CDO.Message")
CDO.Subject = "From Demon wang "
CDO.From = Email_From
CDO.To = Email_To
CDO.TextBody = "Hello world!"
'cdo.AddAttachment = "C:\hello.txt"
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
With CDO.Configuration.Fields
.Item(schema & "sensing") = 2
.Item(schema & "smtpserver") = "smtp.qq.com"
.Item(schema & "smtpauthenticate") = 1
.Item(schema & "sensername") = "123" '注意:是123,而不是Email_From
.Item(schema & "sendpassword") = Password
.Item(schema & "smtpserverport") = 25
.Item(schema & "smtpusessl") = True
.Item(schema & "smtpconnectiontimeout") = 60
.Update
End With
CDO.Send
If Err.Number <> 0 Then
MsgBox "无法发送邮件:" & Err.Description
Else
MsgBox "邮件发送成功", vbInformation
End If
End Sub
热心网友 时间:2022-06-28 19:45
QQ邮箱smtp的端口号为465,而不是25
.Item(schema & "smtpserverport") = 465
热心网友 时间:2022-06-28 19:45
邮箱的smtp服务没有打开