Dan Waters
dwaters at usinternet.com
Mon Mar 1 19:37:33 CST 2010
Hi Rocky,
Sorry - badly worded advice!
What I'd suggest to start with is to get this working in a new mdb. Then
when you know it will work, just move the class module and standard module
over to your mdb. Of course for the standard module you could just put
Public ES As New EmailSMTP
in any standard module.
Because you're setting poSendMail as an object using WithEvents, you must
reference the vbSendMail.dll, which typically you would place in the
System32 folder.
Hope that's better,
Dan
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Rocky Smolin
Sent: Monday, March 01, 2010 4:51 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Email problem. Again
Dan:
If I put that into a class module in a new mdb, how will the app that needs
to send the email 'see' the class module?
"Now put this into a standard module:" in the new mdb, yes?
Does this have to go into a new mdb or can I put it into the application
that I'm trying to fix?
TIA,
Rocky
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Dan Waters
Sent: Monday, March 01, 2010 1:35 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Email problem. Again
Rocky,
Open a new mdb and put this into a class module named 'EmailSMTP':
----------------------------------------------------------
' C Copyright ProMation Systems, Inc.
' Module : EmailSMTP
' Author : Dan Waters
Option Compare Database
Option Explicit
Private WithEvents poSendMail As vbSendMail.clsSendMail
Private Sub poSendMail_SendFailed(Explanation As String)
'-- The SMTPEmailFailed procedure is called so that ErrEx will record
the Call Stack and also the value of Explanation
Call Run("SMTPErrorRaise", 600, "poSendMail_SendFailed", Explanation)
End Sub
'Private Sub poSendMail_Progress(PercentComplete As Long) '
' Debug.Print "poSendMail_Progress " & PercentComplete
'
' Exit Sub
' ErrEx.Bookmark = BOOKMARK_ONERROR
'
'End Sub
'Private Sub poSendMail_SendSuccesful()
'
' Debug.Print "poSendMail_SendSuccesful "
'
' Exit Sub
' ErrEx.Bookmark = BOOKMARK_ONERROR
'
'End Sub
'Private Sub poSendMail_Status(Status As String) '
' Debug.Print "poSendMail_Status " & Status
'
' Exit Sub
' ErrEx.Bookmark = BOOKMARK_ONERROR
'
'End Sub
Public Sub SendEmailsNowSMTP(stgSMTPHost As String, _
stgSMTPFromDisplayName As String, _
stgSMTPFromAddress As String, _
stgSMTPSubject As String, _
stgSMTPRecipientDisplayName As String, _
stgSMTPRecipientAddress As String, _
Optional blnSMTPAsHTML As Boolean, _
Optional stgSMTPMessage As String, _
Optional stgSMTPAttachmentList As String, _
Optional stgSMTPReplyToAddress)
If stgSMTPRecipientDisplayName = "" Or stgSMTPRecipientAddress = "" Or
stgSMTPRecipientAddress = "No Email Address" Then
Call Run("SMTPErrorRaise", 601, "SendEmailsNowSMTP", "Cannot Send
Email")
Exit Sub
End If
Set poSendMail = New vbSendMail.clsSendMail
' -- Set up email paramaters
poSendMail.SMTPHost = stgSMTPHost
poSendMail.RecipientDisplayName = stgSMTPRecipientDisplayName
poSendMail.Recipient = stgSMTPRecipientAddress
poSendMail.FromDisplayName = stgSMTPFromDisplayName
poSendMail.from = stgSMTPFromAddress
poSendMail.Subject = stgSMTPSubject
If Not IsMissing(blnSMTPAsHTML) Then
poSendMail.AsHTML = blnSMTPAsHTML
End If
If Not IsMissing(stgSMTPMessage) Then
If stgSMTPMessage <> "" Then
poSendMail.message = stgSMTPMessage
End If
End If
If Not IsMissing(stgSMTPAttachmentList) Then
If stgSMTPAttachmentList <> "" Then
poSendMail.Attachment = stgSMTPAttachmentList
End If
End If
If Not IsMissing(stgSMTPReplyToAddress) Then
If stgSMTPReplyToAddress <> "" Then
poSendMail.ReplyToAddress = stgSMTPReplyToAddress
End If
End If
'-- When email is originated from the developer's PC, don't actually
send email
If Environ("ComputerName") <> "DanWaters" Then
poSendMail.Connect
DoEvents
poSendMail.Send
DoEvents
poSendMail.Disconnect
DoEvents
End If
Set poSendMail = Nothing
End Sub
----------------------------------------------------------
Now put this into a standard module:
----------------------------------------------------------
Option Compare Database
Option Explicit
Public ES As New EmailSMTP
----------------------------------------------------------
A nice feature of vbSendMail is that it will give you a report of when and
why an SMTP email failed. But you need to use 'WithEvents' in a class
module for this to work.
You must register both the vbSendMail.dll file and the mswinsck.ocx file.
If you comment out the .SMTPHost line, vbSendMail will try to find the host
name. That's OK if there's only one. But if there's more than one and you
want to use a specific host, then you need that host name.
The instruction manual for vbSendMail is really good.
The only significant thing I see different is that I use the
poSendMail.Connect and .Disconnect commands. Can't remember if those are
necessary or not.
Good Luck!
Dan
--
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