Full Version: Sending emails from Access using sendobject
UtterAccess Forums > Microsoft® Access > Access Forms
Squirrel70
Can anyone tell me if they know of any problems using the "SendObject" code
with Outlook? I have a db set up where emails get automatically sent out when
some controls on my form are triggered with certain values. It works
sometimes but sometimes it doesn't. I've tested it and when I close the db
and reopen it then it works once but then I have to close and open the db
again to get it to work again. Any idea what might be causing this? I've also
tested this out on my home pc and it works fine all the time. I'm using the
same version of Access & Outlook. Can anyone shed some light on this for me?
R. Hicks
Yep .. I recommend you read the information at the link below about this method when used in Access 2000 ...
SendObject method fails in Access 2000
RDH
Squirrel70
Thank you for the link. While I'm not very knowledgeable with VBA code I'm assuming I need to add all that code in the "work around" section of that link? Can you give me a quick definition of what all that code will do? Also, will I have to modify any of my existing code for my "SendObject" functions?
R. Hicks
First .. make sure your machine (and all machine that will use this app) has all Service Packs install for Office/Access 2000 ...
You need to be at version SP3 with the latest Jet 4 update installed ...
When if you encounter any problem using the SendObject method .. then you may want to try the workarounds at the link I provided .. or upgrade to a newer version of Access ...
RDH
Squirrel70
I know we are up to only SP1 on our version of Access. Is there anyway to get it to work with the SP1 version that we are currently using? I don't know how long it will take to get everyone up to the SP3 service pack. Why would it work on some machines right now and not others? They are all from the same install of office. Will that workaround work with SP1?
R. Hicks
You need to install SP3 update as there are some "nasty" bugs in Access 2000 that was fixed with this update.
DH
Squirrel70
ok but I've heard that there is a security update that makes a pop-up message appear when sending outlook emails from another application. How do I work around that?
R. Hicks
Two ways I know of is ... using the Click Yes program to click the Yes button for you ..
FOr to use the Redemption method to send the email instead of the SendObject method ...
The Redemption method bypasses the security so the message is not displayed ...
This is a third party .dll file that must be installed and registered on all machines involved.
And .. requires different code ...
RDH
Squirrel70
Where would I find this Click yes program?
R. Hicks
Here is a link to application ...
Express ClickYes
Note ... the message will still appear when sending the email .. this program will simply click the Yes button for you once the progression bar in the warning has completed ...
It will have to be installed on all machines that are to send emails from within Access ...
RDH
Squirrel70
Ok thanks for all your help!
R. Hicks
No problem .. wink.gif
DH
Squirrel70
Someone had mention to me that using CDO would be better than just using the sendobject. Is this true? All I'm trying to do is send automated emails when certain things are filled in on my form or when a new record is created in my form. What do you think?
R. Hicks
I personally use the Redemption dll method to send all of my emails ....
DH
Squirrel70
Would that be easier for me as well?
R. Hicks
I'm not you ...
You have to come to that conclusion for yourself ...
DH
Squirrel70
I wish you were me then I'd know as much as you! Can you point me in the direction where I can read up about this?
R. Hicks
Here is a link to more information ....
What is Outlook Redemption?
RDH
R. Hicks
Here is an example of the code that I use:

CODE
Private Sub SendSafeMail()
im safemail As Variant
Dim myOlApp
Dim MyItem
Dim myRecipient
Dim myBody
Dim myfolder
Dim mynamespace
Dim myAttachments
Dim Utils
Dim strSendTo As String
Dim strCC As String
Dim strAttachPath As String
Dim strAttachPath2 As String

strSendTo = "Someone@Somewhere.com"
[color="green"]'strCC = "SomeoneElse@Somewhere.com"[/color]
strAttachPath = "FullPathToFile"
[color="green"]'strAttachPath2 = "FullPathToFile"[/color]

Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItem(0)
Set safemail = CreateObject("Redemption.SafeMailItem")
Set safemail.Item = MyItem
Set mynamespace = myOlApp.GetNamespace("MAPI")
[color="green"]'mynamespace.Logon "myProfile", "myPassword", True, True ' Choose a Profile[/color]
Set myfolder = mynamespace.GetDefaultFolder(5)

With safemail
  .recipients.Add (strSendTo) ' Send To
  [color="green"]'.CC = strCC ' Carbon Copy[/color]
  .Attachments.Add (strAttachPath) ' Attachment 1
  [color="green"]'.Attachments.Add (strAttachPath2) ' Attachment 2[/color]
  .Subject = "Text For Subject" ' Email Subject Text here
  .Body = "Text Fo Email Body" ' Text for Email Body
  [color="green"]'.Importance = olImportanceHigh  ' High importance[/color]
  .ReadReceiptRequested = True
  .OriginatorDeliveryReportRequested = True
  .Send
End With

Set Utils = CreateObject("Redemption.MAPIUtils")
Utils.DeliverNow

Set myOlApp = Nothing
Set safemail = Nothing
Set Utils = Nothing
MsgBox "Mail Sent", vbInformation, "Mail Sent..."

End Sub

RDH
Squirrel70
ok I'll read up on it. Thanks again!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.