Send emails by calling SMTP Server directly (1 Viewer)

JohnPapa

Registered User.
Local time
Today, 17:59
Joined
Aug 15, 2010
Messages
954
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.
 

isladogs

MVP / VIP
Local time
Today, 15:59
Joined
Jan 14, 2017
Messages
18,253
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
 

isladogs

MVP / VIP
Local time
Today, 15:59
Joined
Jan 14, 2017
Messages
18,253
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
 

isladogs

MVP / VIP
Local time
Today, 15:59
Joined
Jan 14, 2017
Messages
18,253
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
 

JohnPapa

Registered User.
Local time
Today, 17:59
Joined
Aug 15, 2010
Messages
954
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?"
 

cheekybuddha

AWF VIP
Local time
Today, 15:59
Joined
Jul 21, 2014
Messages
2,299
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:59
Joined
Sep 21, 2011
Messages
14,384
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. :(
 

JohnPapa

Registered User.
Local time
Today, 17:59
Joined
Aug 15, 2010
Messages
954
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.
 

JohnPapa

Registered User.
Local time
Today, 17:59
Joined
Aug 15, 2010
Messages
954
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.
 

Lightwave

Ad astra
Local time
Today, 15:59
Joined
Sep 27, 2004
Messages
1,521
I might be tempted to have a field in the database just to record email sent date... as well
 

JohnPapa

Registered User.
Local time
Today, 17:59
Joined
Aug 15, 2010
Messages
954
Most likely I will have a log with the sender, recipient, date-time etc
 

isladogs

MVP / VIP
Local time
Today, 15:59
Joined
Jan 14, 2017
Messages
18,253
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 😊
 

JohnPapa

Registered User.
Local time
Today, 17:59
Joined
Aug 15, 2010
Messages
954
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.
 

isladogs

MVP / VIP
Local time
Today, 15:59
Joined
Jan 14, 2017
Messages
18,253
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
 

JohnPapa

Registered User.
Local time
Today, 17:59
Joined
Aug 15, 2010
Messages
954
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.
 

isladogs

MVP / VIP
Local time
Today, 15:59
Joined
Jan 14, 2017
Messages
18,253
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

  • modEmail.zip
    4.9 KB · Views: 123
Last edited:

JohnPapa

Registered User.
Local time
Today, 17:59
Joined
Aug 15, 2010
Messages
954
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.
 

isladogs

MVP / VIP
Local time
Today, 15:59
Joined
Jan 14, 2017
Messages
18,253
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

  • modEmail.txt
    20.4 KB · Views: 100

JohnPapa

Registered User.
Local time
Today, 17:59
Joined
Aug 15, 2010
Messages
954
Still BitDefender thinks it is a problem. Will try to deactivate or try from another pc.
 

Users who are viewing this thread

Top Bottom