Discussion Locked

Send mail from Access with Outlook Expr.

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

When I try to send mail from access using CDONTS, this code works until I actually get to the "Send" line. Then I get an error message. The documentation from microsoft seems to say that this is not supported from a PC (not a server) in the currentrelease of CDONTS. Any ideas? Installing the full version of Outlook is not an option. Also updating dll's may not be possible. This application is used by external users that are not very computer literate. Getting access to their PC's (300 +)is not easily accomplished.

Function SendNewMail()
Dim objNewMail As Object

On Error GoTo error_olemsg

Set objNewMail = CreateObject("CDONTS.NewMail")

Call objNewMail.AttachFile("C:\Temp\Test.xls", "Test.xls")
objNewMail.From = "person@company.com"
objNewMail.To = "person2@company.com"
objNewMail.Subject = "Territory Planner Changes"
objNewMail.Body = "Territory Planner Changes from Stephen Anderson"
objNewMail.Send
Set objNewMail = Nothing

Exit Function

error_olemsg:
MsgBox "Error " & Str(Err) & ": " & Error$(Err)
Resume Next

End Function

7 replies

by crowmoor

Hi!

I have no experience with CDONTS in Access. I usally uses Docmd.sendobject when sending mail from access and it works for me (well almost there is a rather big bug in the code but search in Microsoft Knowledgebase for Access and SendObject and you get a complete code that you use instead. It works like a charm for me. Sending out about 1500 mails daily with and without attached files.

Hope this could be helpful

Jesper

by sankulpune

Hello andersos,

I have no experience with CDONTS.

But my experience in Access makes me suspect that this problem may be caused by asynchronised execution of the code.

What might possibly is happening that the object objNewMail may be destroyed (set to Nothing) before the action of sending the mail is complete.
(The code
Set objNewMail = Nothing
does not wait to complete the action initiated by the code
objNewMail.Send )

You need to shift the line
Set objNewMail = Nothing
Outside this function (SendNewMail).

You will have to find appropriate event to which you can shift this line.

By the way, I would recommend using a procedure 'Sub SendNewMail()' rather than a function. (I am not sure if this will make any difference.)

SanganakSakha,
Simple And Effective Solutions To Small Problems, No QuickFixes.

by andersos

I can step through the code and I still get an error at the sendmail line. I never get to the line where it sets the object to nothing.

by maxwell edison

Greetings,

This behavior is by design. In order for CDONTS to work properly the SMTP service must be installed.

Adding "IUSR_Machinename" to the admin group resolves the error, but you need to remove the IUSR_Machinename from the admin group for security reasons. In addition, check the IUSR account, and make sure it still has access to all exchange folders and the Metabase.bin file (since you are running CDONTS out of process).

Verify the following settings in the registry:

Verify that the Exchange IMS is installed and functioning.

Verify that HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Exchange\Active Messaging\Use Exchange exists and is set to 1.

Change the access for the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Exchange\Active Messaging key to allow full control to all.

Change the access for the HKEY_LOCAL_MACHINE\SYSTEM\CCS\Services\MSExchangeIMC\Parameters key to allow full control to all.

In Windows Explorer, browse to the folder specified in HKEY_LOCAL_MACHINE\SYSTEM\CCS\Services\MSExchangeIMC\Parameters\RootDir. Give CHANGE permission on the Pickup subdirectory.

For detailed information, see the following article in the Microsoft Knowledge Base:

Q197619 Runtime Error '800a0046' Using the Send Method of CDONTS.NewMail

After following these steps, the same error appears.

When the Windows NT Server Option Pack is installed, select the Upgrade Plus option during setup instead of Upgrade Only option. This option installs the SMTP Service, among others, that is needed for CDONTS for work properly.

Use these steps for another resolution:

Remove "Exchange Internet Mail Connector" via the Exchange Admin.

Install the Option Pack SMTP Service.

Re-install and configure the "Exchange Intenet Mail Connector." NOTE : This will disable the SMTP Service)

From:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q228465

Good luck,

Maxwell

by andersos

I have not tested your answer completely, but it verifies some of the information I have read in the Microsoft Knowledge Base.

This discussion is closed to new replies.