Outlook Email Send not Accepting "To"

rhoekstr

New Member
Joined
Jan 31, 2014
Messages
3
Hello all,

I have a macro that sends automated emails. I am not going to post the entire code because it is quite long... doing things like running of an excel sheet, dynamically updating the email text and a form word document, saving, printing, etc... but this macro worked for months. A few weeks ago, we upgraded from Windows XP to Windows 7. We are using Outlook 2010.

Code:
            Set MailSendItem.SaveSentMessageFolder = olFolder
            With MailSendItem
                .Subject = SubjectDyn
                .HTMLBody = MsgBodyDyn
                .To = Email
                .DeleteAfterSubmit = False
                .Display
                .Send
            End With

The previous code correctly updates and the email and attaches appropriate documents as well as gets the appropriate subject.

The problem I am having is a Runtime Error 5 (invalid procedure call), on the .Send line, but I only get it when sending emails outside of the organization.
So for example, if the first email is to my work address, and my second email is to my personal email... It sends fine on the first email, but I get this error when sending to my personal email.

In troubleshooting, "Email" is correctly set to the email address, but when you open the unsent message, the "To" Line is blank.


Thank you for any help you can provide.
 
I should note that I also rewrote it with using outlook recipient objects and still have the same problem.

Code:
Set olRecipient = .Recipients.Add(Email)
olRecipient.Type = olTo
olRecipient.Resolve
 
Upvote 0
Resolved:

Apparently it is requiring the address not to be in the address book, but to be a name instead of an SMTP address.

Code:
Set MailSendItem.SaveSentMessageFolder = olFolder
            Set olRecipient = MailSendItem.Recipients.Add("'" & Email & "'")
            olRecipient.Type = olTo
            With MailSendItem
                .Subject = SubjectDyn
                .HTMLBody = MsgBodyDyn
                '.To = Email & ";"
                .DeleteAfterSubmit = False
                .Display
                .Send
            End With

The short answer is that the field will not take "abc@gmail.com", but will take "'abc@gmail.com'"

I am marking this as resolved, but if someone can explain why this changed or if there is a way to override needing the apostrophes, I will really appreciate it.
 
Upvote 0

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