Sub CreateHTMLMail()
Dim out As Outlook.Application
Set out = CreateObject("Outlook.Application")
With out.CreateItem(olMailItem)
.Recipients.Add("name1.surname2@alias.com").Type = olTo 'main recipient
.CC = "name2.surname2@alias.com" 'cc recipient
.Subject = "Daily report" 'subject of email
.Body = "Welcome" & vbNewLine & "Please find attached file" & vbNewLine & "Best Regards" & vbNewLine & "MyName"
.Attachments.Add "C:\MyFolder\Report.zip" 'adding file from given folder (insert whole path to file)
'.Send 'sending message
'or just
.Display 'displaying message
End With
Set out = Nothing
End Sub
Sub myexample()
Dim Company1 As New Mailit
Dim Company2 As New Mailit
Company1.RA = "name1.lastname1@Company1.com"
Company1.CC = "name2.lastname2@Company1.com; name3.lastname3@Company1.com; name4.lastname4@Company1.com"
Company1.Subj = "Company1: "
Company2.RA = "name1.lastname1@Company2.com"
Company2.CC = "name2.lastname2@Company2.com; name3.lastname3@Company2.com; name4.lastname4@Company2.com"
Company2.Subj = "Company2: "
Company1.send
Company2.send
End Sub
Paste code below into "class module" and name it "Mailit"
Private pRA As String
Private pCC As String
Private pSubj As String
Public Property Get RA() As String
RA = pRA
End Property
Public Property Let RA(w As String)
pRA = w
End Property
Public Property Get CC() As String
CC = pCC
End Property
Public Property Let CC(w As String)
pCC = w
End Property
Public Property Get Subj() As String
Subj = pSubj
End Property
Public Property Let Subj(w As String)
pSubj = w
End Property
Public Sub send()
Dim out As Outlook.Application
Set out = CreateObject("Outlook.Application")
With out.CreateItem(olMailItem)
.Recipients.Add(RA).Type = olTo
.CC = CC
.Subject = Subj + "Your Message " & Date
.Body = "Good Morning!" & vbNewLine & "Your Message" & vbNewLine & "Best regards" & vbNewLine & "YourName YourLaname"
.Display
End With
Set out = Nothing
End Sub