proper code for sending emails?

jerry12302

Active Member
Joined
Apr 18, 2005
Messages
449
Office Version
  1. 2010
Platform
  1. Windows
Can someone look at this code and tell me if it is appropriate? Is there a better way to do it?

I have been having problems with emails getting through when I use this.

Sub MailerTest()
Dim objol As New Outlook.Application
Dim objmail As MailItem
Set objol = New Outlook.Application
Set objmail = objol.createitem(olmailitem)
With objmail
.To = "someemailaddress@yahoo.com"
.cc = "ccsomeemailaddress@hotmail.com"
.Subject = "Test 12/9 10:39"
.Body = "This is a Test 12/9 10:39"
.NoAging = True
.Attachments.Add "C:\somefile.xls"
.display
End With
Set objmail = Nothing
Set objol = Nothing
SendKeys "%{s}", True
End Sub

Thanks for your help!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I'm not even sure how to know that, I'm sorry to say. I'm not very internet or network savvy when it comes to understanding these things.

I have an AOL account. I recently configured Outlook so I could send and receive (and manage) emails directly from Outlook, instead of having to load AOL. That's all I know, I'm afraid.

I did run AOL and checked my mail, all seems fine. I can send mail from AOL fine. No problems there.
 
Upvote 0
jerry12302 said:
...I can't send emails manually from Outlook anymore either, I've tried several tests and I get the same result....
I think you're going to have to get to where you can send e-mails with Outlook manually before you're going to have any chance of success with this code. If you cannot send e-mails manually, I do not anticipate that e-mails created by code will have any better luck getting through.
 
Upvote 0

Forum statistics

Threads
1,215,672
Messages
6,126,134
Members
449,294
Latest member
Jitesh_Sharma

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