Option Explicit
Private Sub Form_Load()
Dim NameSpace As String
Dim Email As Object
NameSpace = "http://schemas.microsoft.com/cdo/configuration/"
Set Email = CreateObject("CDO.Message")
Text1 = “”‘邮件的内容
With Email
.From = "******" '发件邮箱(此时要改为正确的发件邮箱)
.To = "******" '收件邮箱(此时要改为正确的收件邮箱)
.Subject = "1.txt" '邮件主题
.TextBody = Text1 '邮件内容
With Email.Configuration.Fields
.Item(NameSpace & "sendusing") = 2
.Item(NameSpace & "smtpserver") = "smtp.163.com"
.Item(NameSpace & "smtpserverport") = 25 '端口,不要改!
.Item(NameSpace & "smtpauthenticate") = 1
.Item(NameSpace & "sendusername") = "******@163.com" '邮箱用户名(此时要改为正确的发件邮箱)
.Item(NameSpace & "sendpassword") = "******" '邮箱密码(此处写正确密码)
.Update
End With
.Send
End With
If Err.Number <> 0 Then
MsgBox "无法发送邮件:" & Err.Description
Else
MsgBox "邮件发送成功", vbInformation
End If
Set Email = Nothing
End Sub
联系客服