I am using Joe Was's method to send an email message as below:
Sub Mailer()
'Mails without security alert
'Need reference to Outlook in the Project References
Dim objol As New Outlook.Application
Dim objmail As MailItem
Set objol = New Outlook.Application
Set objmail = objol.CreateItem(olMailItem)
Dim strbody As String
Dim pathname As String
strbody = "Enter Subject Body Here"
pathname = "Pathname of Attachment"
With objmail
'Email To = Email Address in quotes
.To = "Email Address Here"
.CC = "Email Address Here"
.Subject = "Subject" '
'Message Body
.Body = "Message Body" & _
vbCrLf & vbCrLf & strbody & _
vbCrLf & vbCrLf & "Kind Regards" & vbCrLf & _
vbCrLf & "Your Name" & vbCrLf & "Job Title"
'Does not Expire
.NoAging = True
'Read Receipt
.ReadReceiptRequested = True
'adds attachment to email
.Attachments.Add pathname
'Display Email
.Display
End With
Set objmail = Nothing
Set objol = Nothing
'Used for Sending Email Automatically
Application.Wait (Now + TimeValue("0:00:02"))
Application.SendKeys "%s"
Application.Wait (Now + TimeValue("0:00:02"))
SendKeys "%{s}", True 'send the email without prompts
End Sub
It works fine but my message ends up in the outbox in Outlook and does not get sent until I open Outlook. Is there a way to send it directly or is there a way I can open and close Outlook with code so the message will be sent. Thanks for any help you can provide. Frank
Sub Mailer()
'Mails without security alert
'Need reference to Outlook in the Project References
Dim objol As New Outlook.Application
Dim objmail As MailItem
Set objol = New Outlook.Application
Set objmail = objol.CreateItem(olMailItem)
Dim strbody As String
Dim pathname As String
strbody = "Enter Subject Body Here"
pathname = "Pathname of Attachment"
With objmail
'Email To = Email Address in quotes
.To = "Email Address Here"
.CC = "Email Address Here"
.Subject = "Subject" '
'Message Body
.Body = "Message Body" & _
vbCrLf & vbCrLf & strbody & _
vbCrLf & vbCrLf & "Kind Regards" & vbCrLf & _
vbCrLf & "Your Name" & vbCrLf & "Job Title"
'Does not Expire
.NoAging = True
'Read Receipt
.ReadReceiptRequested = True
'adds attachment to email
.Attachments.Add pathname
'Display Email
.Display
End With
Set objmail = Nothing
Set objol = Nothing
'Used for Sending Email Automatically
Application.Wait (Now + TimeValue("0:00:02"))
Application.SendKeys "%s"
Application.Wait (Now + TimeValue("0:00:02"))
SendKeys "%{s}", True 'send the email without prompts
End Sub
It works fine but my message ends up in the outbox in Outlook and does not get sent until I open Outlook. Is there a way to send it directly or is there a way I can open and close Outlook with code so the message will be sent. Thanks for any help you can provide. Frank