PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WD22] SMTP Email sessions
[WD22] SMTP Email sessions
Débuté par Al, 18 mai 2018 04:03 - 7 réponses
Posté le 18 mai 2018 - 04:03
Hello All

I have a question regarding the best method of using smtp email sessions.

My application emails pay slips, chqs and remittance advices.
I do this by initializing the email structure, opening an smtp email session, sending the message, closing the session and then repeating with the next item to send.

I think it would be better to open the smtp session at the beginning, then assemble the data and the pdf into the email variable for the first item, send the message and repeat that process until I have emailed all the items and then close the session.


Regards
Al
Posté le 18 mai 2018 - 09:34
Hi Al,

Indeed. First open te smtp session. If there is any problem with login/password etc... then you will be notified first.

Kind regards,

Joris Martens.
Posté le 18 mai 2018 - 12:42
Hi Al,

I remember that for mass mail, many years ago, I started using one smtp session, send the mails and close the session, because that seemed the logical way to do it.
After I ran into trouble (unfortunately I cannot remember what trouble) the solution was closing and opening the session before each new email.
I found no significant loss of speed in this approach and have been doing it this way ever since.
Opening and closing the session does not clear the email structure, so no problem there too.
I think many may agree that we are often using workarounds that might be obsolete, but it's just not worth the time and effort to check them.

Kind regards,
Piet
Posté le 18 mai 2018 - 13:46
Hi Al,

I remember I had the same result as Piet described, a few years ago. Opening a session once resulted in errors after 20 emails or so. Maybe pcsoft fixed this bug already, but that the problem with pcsoft: no buglists or what so ever.

You should at least add proper errorhandling and save every error (IF NOT EmailStartSMTPSession() THEN ....) in a log file or something like that. Then you will at least get noticed in case of errors.
Posté le 18 mai 2018 - 14:45
i had the same problem a few years ago and the solution was open send close and repeat all the three steps again.

The SMTP server i was using closes the session after aprox. 20 email if i try to send them in the same session, it was not a PCSOFT problem but the SMTP server behaviour.
Posté le 19 mai 2018 - 05:20
Hello All

Thanks for the replies

I raised the issue because I have a client where sometimes the smtp server process returns a "connection failed. No server response" error when sending a batch of emails of between 20 - 100 emails.
They have a 100mb fibre connection so bandwidth shouldn't be an issue

I will try adding a delay period every 15 or so emails and see if that has any effect.

Regards
Al
Posté le 19 mai 2018 - 16:28
When I didn't close the session it would remember the last email address and sent to that as well so be careful.
Posté le 20 mai 2018 - 01:50
Hello Iso

Thanks for the reminder. I will still keep the session open,send email, session close process but see what happens if I introduce a delay after doing this 15 times and then starting another 15 and so - on until they are all done.

It doesn't make much sense logically to so this but sending emails is an arcane art when you have to combine the efforts of so many independent players (Windev, Windows, the user environment, mail servers, internet connections, routers etc) just to get the email out into the world.

Regards
Al