[AccessD] vbSendMail VBA Code (was: Outlook Warninig Message)

Dan Waters dwaters at usinternet.com
Sun Jun 4 11:01:49 CDT 2006


Max - This is what I use within a standard module:

---------------------------------------------------

Public Function SendEmail(stgTo As String, stgEmailAddress As String,
stgSubject As String)

    Dim poSendMail As Object

    If stgTo = "" Or IsNull(stgTo) Then
        Exit Function
    End If

    Set poSendMail = CreateObject("vbSendMail.clsSendMail")
    poSendMail.SMTPHost = SMTPServerName
    poSendMail.FromDisplayName = FullName(CurrentUser)
    poSendMail.FROM = FullName(CurrentUser)
    poSendMail.RecipientDisplayName = stgTo
    poSendMail.Recipient = stgEmailAddress    '-- Or use EmailAddress(stgTo)
    poSendMail.ReplyToAddress = EmailAddress(CurrentUser)
    poSendMail.Subject = stgSubject

    '-- When email is originated from the developer's PC, don't actually
send email
    'If CurrentPCName <> "DanWaters" Then
        poSendMail.Connect
        poSendMail.Send
        poSendMail.Disconnect
    'End If

    Exit Function

End Function

------------------------------------------------------------

SMTPServerName is a sub which looks up the SMTP Server Name from a table.
To send from your PC, you can try something like 'MAIL.USINTERNET.COM',
where USINTERNET is the domain name of your ISP.  In a company environment,
you'll need to work with the IT folks to get the SMTP Server Name.

FullName and EmailAddress are subs which use CurrentUser.  

You can also send strings of multiple names and email addresses.

One thing to note:  VBA Error Trapping will not pick up on vbSendMail
errors.  To get that you'll need to write some WithEvents code, which I'm
not familiar with.  Perhaps if you're familiar with VB6, that won't be a
problem.  Writing this error trapping is described in the vbSendMail
Documentation file, which is pretty good reading. 

*** If anyone does write error trapping for vbSendMail, please post!!  :-)
 
Let me know how this goes,
Dan


-----Original Message-----
Subject: Re: [AccessD] Outlook Warninig Message

Hi Dan,
This works well from outside of Access (using the example exe file).  Do you
have an A3K version (this is VB6 as you know) and it would be nice to have
it within a DB.
Thanks
Max


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Dan Waters
Sent: 03 June 2006 19:23
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Outlook Warninig Message

Hi Rocky,

I use a program called vbSendMail.  You can find it at
http://www.freevbcode.com/ShowCode.Asp?ID=109.

It's free, has great documentation, avoids email applications altogether,
and in 2 1/2 years I've had not one problem.  It's also well documented.

Best of luck!
Dan 
 

-----Original Message-----
 Subject: [AccessD] Outlook Warninig Message

When I try to do automation of access to Outlook, Outlook give the 
warning message:

"A program is trying to access e-mail addresses you have stored in
Outlook.  Do you want to allow this?

You can then choose a number of minutes from a list box to allow the program
to access outlook.

For a program that's supposed to be running unattended, this won't do,
obviously.  Is there a way to disable that message in Outlook?

MTIA

Rocky


-- 
Rocky Smolin
Beach Access Software
858-259-4334
www.e-z-mrp.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list