PDA

View Full Version : Email Run-time error predicament



xjetjockey
06-10-2008, 08:39 AM
I have a befuddling Run-time error when trying to run a simple email routine. I get the following error:

"Run-time error '-2147417851 (80010105)':
Method 'Send' of object '_MailItem' failed"

Here is the Sub


Sub SendEmail()

Dim OutlookApp As Outlook.Application
Dim MItem As Outlook.MailItem

Set OutlookApp = New Outlook.Application
Set MItem = OutlookApp.CreateItem(olMailItem)

With MItem
.To = "myemailaddress@gmail.com"
.Subject = "Subj"
.Body = "This is an email test."
.Send
End With

End Sub

I'm using VBA 6.5 and Excel 2007. Any clue as to what the problem is?

Thanks.

Robert Cooper

Edit: VBA tags added to code

lucas
06-10-2008, 08:43 AM
Robert, I don't have 2007 but it runs ok for me if I set a reference to the MS Outlook object library in the vbe. In the editor go to tools-references...

ps. if you select your code when posting and hit the vba button it will format it as I have done in your first post.

xjetjockey
06-10-2008, 08:56 AM
Thank you very much for your help. Unfortunately the reference was already there. Also, the .save method works, but not the .send method. I wonder if a file is corrupted that needs replacing. What do you think?
Thanks.
Robert

lucas
06-10-2008, 08:59 AM
I don't know. Try this one as it works for me in 2003

xjetjockey
06-10-2008, 09:48 AM
The Display method works, but not the Send method. Really need the Send method to work because this is doing a mass emailing. Did the Send method work on your PC?

lucas
06-10-2008, 10:34 AM
Hi Robert,
Yes, it sent just fine for me. I did get the usual Outlook security popup but it sent the email just fine........

Are you sure you have outlook or maybe just outlook express....that would make a difference.

mdmackillop
06-10-2008, 10:35 AM
No error with 2007, and the email is appearing in my Sent Items folder. However, I'm not receiving the expected "trying to send email" warning, nor am I receiving the emails I send to my account.

xjetjockey
06-10-2008, 10:39 AM
This is Outlook 2007, SP1

mdmackillop
06-10-2008, 11:12 AM
A bit premature, I have received two emails sent by this method.
Save version of Outlook