VBA Emails not going out...

J

Joey Lichtenstein

I have had code to generate alert emails using VBA for years now, but all
of a sudden instead of the alert emails being sent out, they are now
getting stuck in my drafts folder. I have to manually go into the drafts
folder and hit send on each one, which is not what I want!

Any ideas what can cause this? What is really strange is sometimes they
send fine, then sometimes they get stuck.

I had been using the following code (with Outlook Redemption) for years
now without any problems:

Sub MailDoc2(SubjectLine As String, MessageBody As String, Email)
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
myItem.To = Email
myItem.Subject = SubjectLine
myItem.Body = MessageBody
Set myRedMsg = CreateObject("Redemption.SafeMailItem")
myRedMsg.Item = myItem
myRedMsg.Send
End Sub

Thanks very much in advance!

Joey
 
K

Ken Slovak - [MVP - Outlook]

See if issuing a MAPIUtils.DeliverNow helps. You might also have to use a
workaround I've had to use sometimes, getting the Send/Receive or
Send/Receive All CommandBarButton object and calling its Execute method
after using DeliverNow.
 
J

Joey Lichtenstein

Where should I put that in the code?

Stepping through my current code, it takes an extremely long time at the
line:

myRedMsg.Send

Normally it would step through that line as quickly as I can hit "F8", but
now it hangs for 30 seconds to a minute, and the item ends up in the
drafts folder.

What I had been doing for the last several years is setting the
"myItem.To" to the name of a distribution list.

However, I discovered the code actually works when I set the "myItem.To"
variable to a text string of emails. I really prefer the distribution list
to a text string of emails, because the distribution list is so much
easier to maintain.

Any ideas?

: See if issuing a MAPIUtils.DeliverNow helps. You might also have to use a
: workaround I've had to use sometimes, getting the Send/Receive or
: Send/Receive All CommandBarButton object and calling its Execute method
: after using DeliverNow.

: --
: Ken Slovak
: [MVP - Outlook]
: http://www.slovaktech.com
: Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
: Reminder Manager, Extended Reminders, Attachment Options
: http://www.slovaktech.com/products.htm


: :>I have had code to generate alert emails using VBA for years now, but all
:> of a sudden instead of the alert emails being sent out, they are now
:> getting stuck in my drafts folder. I have to manually go into the drafts
:> folder and hit send on each one, which is not what I want!
:>
:> Any ideas what can cause this? What is really strange is sometimes they
:> send fine, then sometimes they get stuck.
:>
:> I had been using the following code (with Outlook Redemption) for years
:> now without any problems:
:>
:> Sub MailDoc2(SubjectLine As String, MessageBody As String, Email)
:> Set myOlApp = CreateObject("Outlook.Application")
:> Set myItem = myOlApp.CreateItem(olMailItem)
:> myItem.To = Email
:> myItem.Subject = SubjectLine
:> myItem.Body = MessageBody
:> Set myRedMsg = CreateObject("Redemption.SafeMailItem")
:> myRedMsg.Item = myItem
:> myRedMsg.Send
:> End Sub
:>
:> Thanks very much in advance!
:>
:> Joey
:>
 
K

Ken Slovak - [MVP - Outlook]

DeliverNow and the possible use of command bars would be after Send.

You may be running into a resolution problem. I almost never use .To myself,
I get a SafeRecipients collection from the item and add each recipient to
that. Then I either resolve each recipient separately or use ResolveAll on
the recipients collection. After that I check for Resolved to make sure the
recipient was resolved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top