这个问题困惑了很久,网上找的答案都不能用,最后自己分析才解决,我用的163邮箱,原来163和qq都关闭了smtp服务器发送的功能,只有yahoo才能用
'邮件发送,参数依次是发送者姓名,收件者姓名,标题,内容,附件,密码
Function sendmail(sendUser,getUser,title,content,txtfile,pwd)
Dim userName '用户名
NameSpace = "http://schemas.microsoft.com/cdo/configuration/"
Set Email = CreateObject("CDO.Message")
userName=Split(sendUser,"@") '得到用户名
Email.From = sendUser '发信人地址
Email.To = getUser '收信人地址
Email.Subject = title '邮件主题
Email.Textbody=content '内容
Email.AddAttachment txtfile '添加附件
with Email.Configuration.Fields
.Item(NameSpace&"sendusing") = 2
.Item(NameSpace&"smtpserver") = "smtp.mail.yahoo.com.cn" '这是yahoo邮箱的服务器地址
.Item(NameSpace&"smtpserverport") = 25
.Item(NameSpace&"smtpauthenticate") = 1
.Item(NameSpace&"sendusername") = userName(0)'发信人用户名
.Item(NameSpace&"sendpassword") = pwd '发信人密码
.Update
End With
Email.Send
Set Email=Nothing
End Function
sendmail "dfgf@yahoo.com.cn","dfdf@yahoo.com.cn","thisis me","hahahahha","d:\test11.txt","dfdfd"