Send emails by calling SMTP Server directly

One more question: Does anyone know if I can see the sent emails somewhere? I looked at the Webmail of my ISP for the account that I used to authenticate and there was nothing there.
 
I downloaded the example you mention, I ran it. Nothing happens when I click on any of the buttons "Send Email", "Help", "Quit"

That's because you haven't done one or both of the following:

1. Due to changes introduced by MS a few months ago, all files downloaded from the Internet must now be unblocked before they can be used.

1668351612700.png


2. You will also need to Enable Content or save to a trusted location.

Once done, the code will run
 
I tried the following, but unfortunately does not send. The xxx, were replaced for valid email addresses.

It tells me "The transport failed to connect to the server"

Read the Help file that is supplied with the app - it goes through all the possible reasons why email doesn't send
This is the first item listed!

1668351855732.png
 
It was a problem with the trusted location. I would have expected a message. It now gives one of the errors which appear in the documentation.
You will only get the yellow Enable Content security banner if your Macro Settings in the Trust Center are set to the following:

1668352079448.png
 
BCC yourself?
Thanks for the obvious solution. Short of BCCing every email, the question still stands "Are the outgoing emails stored somewhere and can they be accessed?"
 
Thanks for the obvious solution. Short of BCCing every email, the question still stands "Are the outgoing emails stored somewhere and can they be accessed?"
No.

You would need to use something else like MAPI to write the email to Sent folder on the server. It starts getting complicated in terms of Access/VBA/Windows security settings blocking this. By this stage you may as well use a third-party solution or, even worse, automate Outlook.

BCC'ing yourself is infinitely easier, you can always create a rule in your normal email client to move these emails to a dedicated folder
 
Thanks for the obvious solution. Short of BCCing every email, the question still stands "Are the outgoing emails stored somewhere and can they be accessed?"
You would be surprised how many people do not think of the 'obvious' solution. :(
 
No.

You would need to use something else like MAPI to write the email to Sent folder on the server. It starts getting complicated in terms of Access/VBA/Windows security settings blocking this. By this stage you may as well use a third-party solution or, even worse, automate Outlook.

BCC'ing yourself is infinitely easier, you can always create a rule in your normal email client to move these emails to a dedicated folder
Many thanks for the reply. The software works right now with Outlook and we want to make it SMPT Client Independent.

So I guess BCC is the most practical solution.
 
You would be surprised how many people do not think of the 'obvious' solution. :(
Indeed, sometimes the obvious solution is not that obvious.

Let me share some details. I have developed a software package which can send Reminder Emails and/or Text messages for such tasks as alert for product license expiry. The software is also used to send Campaign information and/or general information. For the latter task and to avoid spam issues the recipient email addresses are grouped in a user-specified number (say 10) and are send as BCC in the email and the user can specify a delay between the sending of the emails (say 10 seconds.) The "To" email address is usually the user's email address, hence the user has a record of what was sent. Your very practical suggestion is to include the user's email in the BCC, which would work very nicely.
 
I might be tempted to have a field in the database just to record email sent date... as well
 
Most likely I will have a log with the sender, recipient, date-time etc
 
Just FYI, I started using CDO in 2005 with one of my schools databases when a new IT manager decided to remove Outlook and replace it with Novell Groupwise. We were unable to get that to work with Access so moved over to CDO. I have never seen a reason to switch back

CDO can do almost anything that you can do using Outlook automation except (as discussed) it doesn't save a copy of the email sent. Nor can it receive email.

As suggested above, we included an option for users to send a copy of the email to themselves.
That mostly worked fine for those who needed it

However one of our client schools asked for the option to use CDO with Outlook. This may seem pointless, but the idea was that the email was constructed in Access (title/subject/ formatting/recipient list/attachments/images but actually sent via Outlook so as to retain a copy automatically.

So in addition to the SendEMail procedure used in my CDO EMail Tester example app, I provided 2 additional optional procedures for doing this:
a) SendEmailDisplayOutlook - show user the Outlook message for final editing before sending
b) SendEmailUsingOutlook - send message via Outlook but without showing Outlook

That covered all possible approaches 😊
 
Very useful. I am guessing that the last 2 procedures are not available in the tester app.

I already have it working using Outlook, with and without showing the email prior to sending the email.
 
They aren't in the tester app but I'm happy to share them if they would be useful.
However, it sounds like you've already achieved the same results yourself
 
They aren't in the tester app but I'm happy to share them if they would be useful.
However, it sounds like you've already achieved the same results yourself
They would be useful if I also decide to adopt CDO completely, which is a more professional way to go, since it should not be expected for the user to have Outlook.

Also, can you please shed some light on the difference between Local and Network. Thanks.
 
Attached is a zipped .bas file containing most of the module code I used.
I've stripped out a few items that are irrelevant but there is still much you probably won't need.
The code compiles so hopefully it will work as written but I haven't touched it in almost 15 years!

NOTE: I use late binding for anything invoking CDO or Outlook so no additional references are needed

The SendUsing setting is almost always 2 (Network)
The possible values are:
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Two CDO articles you may find helpful:
Sending Emails from Access with VBA and CDO - Codekabinett

VBA - Using CDO Mail To Send E-mails | DEVelopers HUT (devhut.net)

Hope that helps. Ask if you have any other questions
 

Attachments

Last edited:
Attached is a zipped .bas file containing most of the module code I used.
I've stripped out a few items that are irrelevant but there is still much you probably won't need.
The code compiles so hopefully it will work as written but I haven't touched it in almost 15 years!

NOTE: I use late binding for anything invoking CDO or Outlook so no additional references are needed

The SendUsing setting is almost always 2 (Network)
The possible values are:
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Two CDO articles you may find helpful:
Sending Emails from Access with VBA and CDO - Codekabinett

VBA - Using CDO Mail To Send E-mails | DEVelopers HUT (devhut.net)

Hope that helps. Ask if you have any other questions
Many thanks for the info. I cannot download the attachment, my BitDefender is informing me that the web page is infected.

Also thanks for clarifying Local Vs Network. I thought that the local and network referred to the pc that was accessing the smtp server, not the smtp server itself.

It is good you use late binding. Fewer complications.
 
Hmm....
Its just a plain text file with a .bas file suffix and has had 13 downloads so far
I've renamed it as .txt - hopefully that will be OK for you
 

Attachments

Still BitDefender thinks it is a problem. Will try to deactivate or try from another pc.
 

Users who are viewing this thread

Back
Top Bottom