怎么向邮箱发送邮件,怎么给别人的邮箱发送邮件

首页 > 数码 > 作者:YD1662024-05-07 11:17:41

工作中经常需要发送邮件,每次都需要登录邮箱很是麻烦,有没有一种简单的方式发送邮件呢,答案当然是有的啦,下面是笔者用Excel VBA 的方法进行邮件发送,简直不要太方便。

首先,新建或打开一个已有的Excel 文件,这里新建一个Excel文件,名称为datafile.xlsx,在sheet1工作表中编辑内容如下:

怎么向邮箱发送邮件,怎么给别人的邮箱发送邮件(1)

第二,打开VBA编辑器,插入一个模块,输入如下代码:

Sub SendEmail()

'定义变量

Dim receiver As String

Dim subjecttext As String

Dim bodytext As String

Dim attachedobject1 As String

Dim attachedobject2 As String

Dim attachedobject3 As String

Dim attachedobject4 As String

Dim OutlookApp As Outlook.Application

Dim OutlookItem As Outlook.mailItem

Dim sh As Worksheet

'给变量赋值

Set sh = Sheets(1)

Set OutlookApp = New Outlook.Application

Set OutlookItem = OutlookApp.CreateItem(olMailItem)

receiver = sh.[B1].Value

subjecttext = sh.[B2].Value

bodytext = sh.[B3].Value

attachedobject1 = sh.[B4].Value

attachedobject2 = sh.[B5].Value

attachedobject3 = sh.[B6].Value

attachedobject4 = sh.[B7].Value

On Error GoTo SendEmail_Error

With OutlookItem

.To = receiver

.Subject = subjecttext

.Body = bodytext

If attachedobject1 <> "" Then

.Attachments.Add attachedobject1

.Attachments.Add attachedobject2

.Attachments.Add attachedobject3

.Attachments.Add attachedobject4

End If

.send

MsgBox "Sent sucessfully"

End With

SendEmail_Exit:

Exit Sub

SendEmail_Error:

MsgBox Err.Description

Resume SendEmail_Exit

End Sub

怎么向邮箱发送邮件,怎么给别人的邮箱发送邮件(2)

第三,点击运行,一键发送:

怎么向邮箱发送邮件,怎么给别人的邮箱发送邮件(3)

打开邮箱查收邮件:

怎么向邮箱发送邮件,怎么给别人的邮箱发送邮件(4)

怎么向邮箱发送邮件,怎么给别人的邮箱发送邮件(5)

只需三步,即可一键发送邮件。

友友,还不赶快行动起来试试吧。

记得关注、点赞、评论、收藏哟!

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.