Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29935

Sending Outlook Email With Attachment Through VBA

$
0
0

I would like a macro to email a report through Outlook after it has finished.

I am testing this with my own and coworker's email addresses and I am getting an "Undeliverable"Error.

The message says the recipient cannot be reached and suggests trying to send the email later.

I would greatly appreciate it if the community would take a look at the code I have produced so far and let me know if it is my code or maybe the system that is causing the error. (I have a strong feeling it is the code!)

Sub CreateEmail()

Dim OlApp As Object
Dim OlMail As Object
Dim ToRecipient As Variant
Dim CcRecipient As Variant

Set OlApp = CreateObject("Outlook.Application")
Set OlMail = OlApp.createitem(olmailitem)

For Each ToRecipient In Array("jon.doe@aol.com")
    OlMail.Recipients.Add ToRecipient
Next ToRecipient

For Each CcRecipient In Array("jon.doe@aol.com")
    With OlMail.Recipients.Add(CcRecipient)
        .Type = olCC
    End With
Next CcRecipient

'Fill in Subject field
OlMail.Subject = "Open Payable Receivable"'Add the report as an attachment

OlMail.Attachments.Add ("C:\OpenPayRecPrint2.pdf")

'Send Message

OlMail.Send

End Sub

Viewing all articles
Browse latest Browse all 29935

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>