Sub SendToMail()
If Range("A1")>=5 Then Exit Sub '假如需要检测的是A1单元格数据,可自行修改
Set Email = CreateObject("CDO.Message")
qq="XXX"'这里是你的qq号码
pass="***"'这里输入你的密码
strName = "
Email.From = qq&"@qq.com"
Email.To = "XXXXXXXXXX@qq.com"'目的邮箱地址
'Email.cc="XXXXX@qq.COM" '抄送
Email.Subject = ZhuTi '邮件的主题
Email.Textbody =XXX '邮件内容
With Email.Configuration.Fields
.Item(strName & "sendusing") = 2
.Item(strName & "smtpserver") = "smtp.qq.com"
.Item(strName & "smtpserverport") = 25
.Item(strName & "smtpauthenticate") = 1
.Item(strName & "sendusername") = qq
.Item(strName & "sendpassword") = pass
.Update
End With
Email.Send
End Sub
试试这个代码
Sub 发邮件()
Dim ou As Object
Dim oua As Object
Dim a As Integer
If a < 5 Then '设置条件,当a小于5的时候发邮件
Set ou = CreateObject("outlook.application")
Set oua = ou.CreateItem(0)
With oua
.To = "xxx@xxx.com" '收件人
.Subject = "Hello" '题目
.Body = "Send Test" '内容
.display
.Send '发送
End With
End If
End Sub