作者:乔山办公网日期:
返回目录:excel表格制作
这个不难,不但可以设置邮件正文,甚至可以设置其中的格式。看下私信。
1.添加引用Microsoft Outlook 11.0 Object Library。(这里用的是Microsoft Outlook
2003)
2.定义发送e79fa5e98193e58685e5aeb9339邮件过程。
Public Sub SendEmail(Receiver As String, SubjectText As String, BodyText As
String, AttachedObject As String)
Dim OutlookApp As
Outlook.Application
Dim OutlookItem As
Outlook.MailItem
Set OutlookApp =
New Outlook.Application
Set OutlookItem =
OutlookApp.CreateItem(olMailItem)
On Error GoTo
SendEmail_Error
With
OutlookItem
.To = Receiver
'收件人地址
.Subject = SubjectText
'邮件主题
.Body = BodyText
'邮件内容
.Attachments.Add
AttachedObject '粘贴附件
.Send
'发送邮件
End With
SendEmail_Exit:
Exit
Sub
SendEmail_Error:
MsgBox
Err.Description
Resume SendEmail_Exit
End Sub
Set olApp = CreateObject("Outlook.Application")
Set newItem = olApp.CreateItem(olMailItem)
newItem.To = "邮箱地百址度,多个地知址以道分号回隔答开"
newItem.Subject = "abc"
newItem.Body = "abc"
newItem.Send
Excel里发邮件试试 Jmail 这个组件吧,最新版为4.5,完全免费,只有314K大,功能比Outlook强大,而且好用,不会出错。有兴趣的话可以给你一个Excel做好的邮件发送程序。
Function JmailSend(Subject, Body, isHtml, HtmlBody, MailTo, RecipientCC, RecipientBCC, From, FromName, Smtp, Username, Password, IsAF, AttachFile1, AttachFile2, AttachFile3, AttachFile4, AttachFile5)
'=================================================
'函数名:JmailSend
'作 用:用Jmail发送邮件
'参 数:Subject 邮件标题
' Body 邮件内容
' isHtml 是否发送Html格式邮件 (True 是)
' HtmlBody Html格式邮件内容
' MailTo 收件人Email
' From 发件人Email
' FromName 发件人姓名
' Smtp Smtp服务器
' Username 邮箱用户名
' Password 邮箱密码
' IsAF 是否有附件,逻辑值
' AttachFile 附件路径
'返回值:JmailSend="N" 发送失败 JmailSend="Y" 发送成功
'=================================================
Dim JmailMsg
'Set JmailMsg = server.CreateObject("jmail.message")
Set JmailMsg = New jmail.Message
JmailMsg.MailServerUserName = Username '如果是在局域网中可以不要验证
JmailMsg.MailServerPassWord = Password
JmailMsg.Logging = True '是否使用日志
Arymailto = Split(MailTo, ",")
For i = 0 To (UBound(Arymailto) - 1) / 2
JmailMsg.AddRecipient Trim(Arymailto(i * 2 + 1)), Trim(Arymailto(i * 2)) '添加收件人
Next
If RecipientCC <> "" Then
AryCC = Split(RecipientCC, ",")
For i = 0 To (UBound(AryCC) - 1) / 2
JmailMsg.AddRecipientCC Trim(AryCC(i * 2 + 1)), Trim(AryCC(i * 2)) '添加抄送地址
Next
End If
If RecipientBCC <> "" Then
AryBCC = Split(RecipientBCC, ",")
For i = 0 To (UBound(AryBCC) - 1) / 2
JmailMsg.AddRecipientBCC Trim(AryBCC(i * 2 + 1)), Trim(AryBCC(i * 2)) '添加密送地址
Next
End If
JmailMsg.From = From
JmailMsg.FromName = FromName
JmailMsg.Encoding = "base64" '设置编码
JmailMsg.Charset = "gb2312"
JmailMsg.Priority = 1 '设置邮件的e799bee5baa6e79fa5e98193e78988e69d83361优先级
JmailMsg.Silent = True '安静模式
JmailMsg.Subject = Subject
JmailMsg.Body = Body
If IsAF Then '邮件是否有附件
If AttachFile1 <> "" Then
JmailMsg.AddAttachment (AttachFile1) '附件
End If
If AttachFile2 <> "" Then
JmailMsg.AddAttachment (AttachFile2) '附件
End If
If AttachFile3 <> "" Then
JmailMsg.AddAttachment (AttachFile3) '附件
End If
If AttachFile4 <> "" Then
JmailMsg.AddAttachment (AttachFile4) '附件
End If
If AttachFile5 <> "" Then
JmailMsg.AddAttachment (AttachFile5) '附件
End If
End If
If isHtml = True Then JmailMsg.HtmlBody = HtmlBody
If Not JmailMsg.Send(Smtp) Then
JmailSend = "N"
Else
JmailSend = "Y"
End If
JmailMsg.Close
Set JmailMsg = Nothing
'MsgBox (JmailSend) '测试时可以用
End Function