INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Sending email with Outlook 2010 - keeps giving run-time error 287

Sending email with Outlook 2010 - keeps giving run-time error 287

(OP)
Ok, I'm at my wits end... this SHOULD be so simple, yet I've beat my head against a brick wall....

I'm trying to set up a function in my project to send emails using Microsoft Outlook 2010, and every code example I find fails.

My specs:
Windows 7 64bit
Visual Basic 6 / Visual Studios 6
I have referenced the Microsoft Outlook 14.0 Object Library (msoutl.olb)

Here's my function code

CODE

Public Function SENDOUTLOOKEMAIL(ByVal OUTEMLIST As String, ByVal OUTSUBJ As String, ByVal OUTMSSG As String, ByVal OUTFILES As String) As Boolean
Dim oApp As Outlook.Application
Dim oEmail As Outlook.MailItem
Set oApp = New Outlook.Application
Set oEmail = oApp.CreateItem(olMailItem)
With oEmail
    If BCCIT = True Then
        .BCC = OUTEMLIST
    Else
        .To = OUTEMLIST
    End If
    .Subject = OUTSUBJ
    .Body = OUTMSSG
    .Recipients.ResolveAll
    .SAVE
    On Error Resume Next
    .Send
    If Err <> 0 Then
        X = MsgBox("Error Occured: " + Err.Description)
        Err.Clear
        SENDOUTLOOKEMAIL = False
    Else
        X = MsgBox("Email Successfully Sent!!", vbInformation)
        SENDOUTLOOKEMAIL = True
    End If
End With
Set oEmail = Nothing
oApp.Quit
Set oApp = Nothing
    
Exit Function 

It gets to .Recipients.ResolveAll, then gives a "Run-time error '287': Application-defined or object-defined error"

I'm not sure what else to do :(

Any help would be GREATLY appreciated....also, my workplace is getting Office 2013... this script SHOULD work the same with Outlook 2013, right?

------------------------------------
yinyang Over 20 years of programming, and still learning every day! yinyang

RE: Sending email with Outlook 2010 - keeps giving run-time error 287

(OP)
Correction to the function header...

CODE

Public Function SENDOUTLOOKEMAIL(ByVal OUTEMLIST As String, ByVal OUTSUBJ As String, ByVal OUTMSSG As String, ByVal OUTFILES As String, ByVal BCCIT as Boolean) As Boolean 

------------------------------------
yinyang Over 20 years of programming, and still learning every day! yinyang

RE: Sending email with Outlook 2010 - keeps giving run-time error 287

This is what I use to send e-mails from my code.
You just need to set your cdoSMTPServer and pass some parameters into this Sub.


CODE


'''Add Referebce to: Microsoft CDO For Windows 2000 Library

Public Sub SendAMessage(strFrom As String, strTo As String, _
    strCC As String, strSubject As String, strTextBody As String, _
    Optional strBcc As String, Optional strAttachDoc As String)

Dim objMessage As CDO.Message

On Error GoTo MyErrorHadler

Set objMessage = New CDO.Message

With objMessage
    .From = strFrom
    .To = strTo
    If Len(Trim$(strCC)) > 0 Then
        .CC = strCC
    End If
    If Len(strBcc) > 0 Then
        .BCC = strBcc
    End If
    ''' On behalf of
    '.Sender = "Bill.Gates@msn.com"
    .Subject = strSubject
    .TextBody = strTextBody
    
    If Len(strAttachDoc) > 0 Then
        .AddAttachment strAttachDoc
    End If
    
    With .Configuration.Fields
        .Item(CDO.cdoSMTPServer) = "YOUR.SMTP.SERVER.LAN"
        .Item(CDO.cdoSMTPServerPort) = 25
        .Item(CDO.cdoSendUsingMethod) = CDO.cdoSendUsingPort
        .Item(cdoSMTPConnectionTimeout) = 10
        .Update
    End With
    .Send
End With

Set objMessage = Nothing

Exit Sub
MyErrorHadler:

'' Do something here in case of an error

Resume Next

End Sub 

You may also want to contact your e-mail admin to allow your application to send e-mails this way. (because you can send a LOT of e-mails this way, i.e. SPAM)

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

RE: Sending email with Outlook 2010 - keeps giving run-time error 287

(OP)
Thank you for the reply Andrzejek!

I've seen examples of the CDO sending method, however I'm not able to use that in the environment where this script will be used :(

I do appreciate the suggestion though :)

------------------------------------
yinyang Over 20 years of programming, and still learning every day! yinyang

RE: Sending email with Outlook 2010 - keeps giving run-time error 287

Oh, I'd imagine this is Outlook's security settings.

You could try set Allow Programmatic Access in Outlook to 'always' or 'yes'. (not best practice, but it would at least let us verify whether this is the issue)

RE: Sending email with Outlook 2010 - keeps giving run-time error 287

(OP)
Thanks for the reply strongm!

Tried messing with trust center settings but to no avail.

One thing I DID discover is that if outlook is running, the email sends just fine. When I close out outlook and try to send, I get the error message again.

Probably something in the settings that I'm just not seeing?

Also, I've tried this very same script on another partition that's running Office 2013 now, and it works just fine, whether out look is open or closed.

Again... I'm leaning more toward some obscure outlook setting that I'm not familiar with...

------------------------------------
yinyang Over 20 years of programming, and still learning every day! yinyang

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close