forked from farishadi/Excel_Macro_References
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendEmailViaVBAMethod3
More file actions
39 lines (33 loc) · 1.04 KB
/
SendEmailViaVBAMethod3
File metadata and controls
39 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Public Sub SendMailO365()
'This method sends email via Outlook365 without the need for user's username and password
'The "From" field accepts any value as long as it contains "@" and ".", recommend maintain with noreply@org.com
'Declare Send Mail Property
Dim oConf As Object
Set oConf = CreateObject("CDO.Configuration")
'CDO Source Defaults
oConf.Load -1
With oConf.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = serverPath
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = serverPort
.Update
End With
'Create email
Dim oMsg As Object
Set oMsg = Nothing
Set oMsg = CreateObject("CDO.Message")
'Set iConf = CreateObject("CDO.Configuration")
With oMsg
Set .Configuration = oConf
.To = ""
.CC = ""
'.BCC = ""
.From = ""
.Subject = ""
.BodyPart.Charset = "utf-8" 'to accept chinese characters
.HTMLBody = ""
'.TextBody = ""
'.AddAttachment (fullAttachmentPath)
.Send
End With
End Sub