Send Mail help (1 Viewer)

gmatriix

Registered User.
Local time
Today, 18:44
Joined
Mar 19, 2007
Messages
365
Hello All,

Trying to figure out why this code is not working.

Code:
Function SendMail()
Dim outl As outlook.Application
Set outl = New outlook.Application
Dim mi As outlook.MailItem
Set mi = outl.CreateItem(olMailItem)
mi.body = "Hello, blah blah blah"
mi.Subject = "CV_blah"
mi.To = "blah@blah.com"
mi.Send
Set mi = Nothing
Set outl = Nothing
End Function

Any Ideas?
 

Ranman256

Well-known member
Local time
Today, 18:44
Joined
Apr 9, 2015
Messages
4,337
does the code stop on a line to tell you WHERE its not working?

Mine works, usage:
call Email1("bob@aol.com","Subject","Body")
Code:
'-------
'YOU MUST ADD THE OUTLOOK APP IN REFERENCES!!!   checkmark MICROSOFT OUTLOOK OBJECT LIBRARY in the vbE menu, Tools, References
'-------

Public Function Email1(ByVal pvTo, ByVal pvSubj, ByVal pvBody) As Boolean
Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem

On Error GoTo ErrMail

Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(olMailItem)

With oMail
    .To = pvTo
    .Subject = pvSubj
    .Body = pvBody

    .Attachments.Add "c:\temp\file.xls", olByValue, 1
    
    .Send
End With

EmailO = True
Set oMail = Nothing
Set oApp = Nothing
Exit Function

ErrMail:
MsgBox Err.Description, vbCritical, Err
Resume Next
End Function
 

gmatriix

Registered User.
Local time
Today, 18:44
Joined
Mar 19, 2007
Messages
365
Yeah, it says User Defined Not Defined here:
Dim outl As outlook.Application


Tried yours...did not work...says something about wrong number of arguments...
 
Last edited:

gmatriix

Registered User.
Local time
Today, 18:44
Joined
Mar 19, 2007
Messages
365
I got it to work....

did not check the reference.....it works now
 

Users who are viewing this thread

Top Bottom