E-mail message

farmock

Board Regular
Joined
Sep 10, 2006
Messages
60
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
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hatman,
Thanks for the response. I'm new at this and am not sure where the attachmnet file names get entered. Thanks for all the help! Frank
 
Upvote 0
Check out the Sample_Call routine at the end of the code... it shows how to attach 2 files.

Alternatively, to attach a single file, simply assign a single value to the variable.

Even more simply:
Code:
    Send_New_Mail "paul.sasur@hs.utc.com", "SUBJECT", "Body Text Here", "c:\temp\sample file.txt"
 
Upvote 0
Hatman,
When I run the program when it gets to the line near the end "If OlbCreated Then OutApp.Quit" I get a message asking if I want to save "subject". If I save it, it shows up in Outlook in the inbox with the message "This mail has not been sent". If I don't save it, it doesn't show up at all and doesn't get sent. Any thoughts on what I might be doing wrong? Thanks for the help. Frank
 
Upvote 0

Forum statistics

Threads
1,214,801
Messages
6,121,644
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top