Archived Forum Post

Index of archived forum posts

Question:

Sending multiple emails with one connection? ActiveX Email control

May 08 '15 at 02:23

Is it possible to send multiple outgoing emails to a SMTP server in one connection? I have a user who sends lots of emails and uses Google, Google has told him the emails should be sent all in one connection instead of one connection per email.

Would putting a loop like below use the same connection or create a new connection for each email?

'  Use the GMail SMTP server
mailman.SmtpHost = "smtp.gmail.com"
mailman.SmtpPort = 465
mailman.SmtpSsl = 1

'  Set the SMTP login/password.
mailman.SmtpUsername = "chilkat.support"
mailman.SmtpPassword = "myPassword"

**for a = 1 to 1000**

Dim email As New ChilkatEmail2
email.Subject = "This is a test" & a
email.Body = "This is a test" & a
email.From = "Chilkat Support <chilkat.support@gmail.com>"
email.AddTo "Chilkat","support@chilkatsoft.com"

success = mailman.SendEmail(email)
If (success <> 1) Then
    MsgBox mailman.LastErrorText
    Exit Sub
End If
**next a**

Answer

Yes, the Chilkat mailman will by-default keep the connection open with the SMTP server after an email is sent. This allows for a subsequent email to be sent on the same connection.

Make sure your program uses the same mailman object instance for each send. If you use different mailman instances, then each will have its own connection.


Answer

Would a loop like below use the same connection also? I realized my code already has a loop similar to below... will setting the mailmain host and password setting to the same value cause it to drop the current connection and create a new one on each pass? How long is a connection left open before it drops?

**for a = 1 to 1000**
'  Use the GMail SMTP server
mailman.SmtpHost = "smtp.gmail.com"
mailman.SmtpPort = 465
mailman.SmtpSsl = 1

'  Set the SMTP login/password.
mailman.SmtpUsername = "chilkat.support"
mailman.SmtpPassword = "myPassword"

Dim email As New ChilkatEmail2
email.Subject = "This is a test" & a
email.Body = "This is a test" & a
email.From = "Chilkat Support <chilkat.support@gmail.com>"
email.AddTo "Chilkat","support@chilkatsoft.com"

success = mailman.SendEmail(email)
If (success <> 1) Then
    MsgBox mailman.LastErrorText
    Exit Sub
End If
**next a**

Answer

There is no limit as to how long the connection is left open. Chilkat doesn't close it after any period of time.

If the connection is lost, the next call to SendEmail should automatically reconnect.

One more thing -- make sure to change the recipient for each loop iteration, otherwise the result will not be good...


Answer

The results I am getting are not what you are describing, below is a log file from a test I ran on an SMTP server on my server computer. I had a loop of 250 emails and as you can see from the log Chilkat is sending a "Quit" after every email.

My code uses the same Mailman object instance, it is exactly like the code I pasted earlier. I tried with the loop including the setting of the host,port, ssl , user and pass and with those values set before the loop and get the same results both ways.

Any ideas?

"SMTPD" 1536    8002    "2013-04-30 12:17:37.935"   "184.89.67.60"  "SENT: 220 smtp.mysite.com ESMTP"
"SMTPD" 1520    8002    "2013-04-30 12:17:37.982"   "184.89.67.60"  "RECEIVED: EHLO Office1"
"SMTPD" 1520    8002    "2013-04-30 12:17:37.982"   "184.89.67.60"  "SENT: 250-smtp.mysite.com[nl]250-SIZE 20480000[nl]250 AUTH LOGIN"
"SMTPD" 1556    8002    "2013-04-30 12:17:38.013"   "184.89.67.60"  "RECEIVED: AUTH LOGIN"
"SMTPD" 1556    8002    "2013-04-30 12:17:38.013"   "184.89.67.60"  "SENT: 334 VXNlcm5hbWU6"
"SMTPD" 1560    8002    "2013-04-30 12:17:38.044"   "184.89.67.60"  "RECEIVED: cm9uQHJ0b3Byby5jb20="
"SMTPD" 1560    8002    "2013-04-30 12:17:38.044"   "184.89.67.60"  "SENT: 334 UGFzc3dvcmQ6"
"SMTPD" 1532    8002    "2013-04-30 12:17:38.091"   "184.89.67.60"  "RECEIVED: ***"
"SMTPD" 1532    8002    "2013-04-30 12:17:38.091"   "184.89.67.60"  "SENT: 235 authenticated."
"SMTPD" 1536    8002    "2013-04-30 12:17:38.123"   "184.89.67.60"  "RECEIVED: MAIL FROM:<sales@mysite.com>"
"SMTPD" 1536    8002    "2013-04-30 12:17:38.138"   "184.89.67.60"  "SENT: 250 OK"
"SMTPD" 1552    8002    "2013-04-30 12:17:38.169"   "184.89.67.60"  "RECEIVED: RCPT TO:<me@mysite.com>"
"SMTPD" 1552    8002    "2013-04-30 12:17:38.169"   "184.89.67.60"  "SENT: 250 OK"
"SMTPD" 1512    8002    "2013-04-30 12:17:38.201"   "184.89.67.60"  "RECEIVED: RCPT TO:<me@mysite.com>"
"SMTPD" 1512    8002    "2013-04-30 12:17:38.201"   "184.89.67.60"  "SENT: 250 OK"
"SMTPD" 1568    8002    "2013-04-30 12:17:38.248"   "184.89.67.60"  "RECEIVED: DATA"
"SMTPD" 1568    8002    "2013-04-30 12:17:38.248"   "184.89.67.60"  "SENT: 354 OK, send."
"SMTPD" 1304    8002    "2013-04-30 12:17:38.326"   "184.89.67.60"  "SENT: 250 Queued (0.079 seconds)"
"SMTPD" 1528    8002    "2013-04-30 12:17:38.373"   "184.89.67.60"  "RECEIVED: QUIT"
"SMTPD" 1528    8002    "2013-04-30 12:17:38.373"   "184.89.67.60"  "SENT: 221 goodbye"
"SMTPD" 1536    8003    "2013-04-30 12:17:39.732"   "184.89.67.60"  "SENT: 220 smtp.mysite.com ESMTP"
"SMTPD" 1548    8003    "2013-04-30 12:17:39.763"   "184.89.67.60"  "RECEIVED: EHLO Office1"
"SMTPD" 1548    8003    "2013-04-30 12:17:39.763"   "184.89.67.60"  "SENT: 250-smtp.mysite.com[nl]250-SIZE 20480000[nl]250 AUTH LOGIN"
"SMTPD" 1540    8003    "2013-04-30 12:17:39.810"   "184.89.67.60"  "RECEIVED: AUTH LOGIN"
"SMTPD" 1540    8003    "2013-04-30 12:17:39.810"   "184.89.67.60"  "SENT: 334 VXNlcm5hbWU6"
"SMTPD" 1568    8003    "2013-04-30 12:17:39.841"   "184.89.67.60"  "RECEIVED: cm9uQHJ0b3Byby5jb20="
"SMTPD" 1568    8003    "2013-04-30 12:17:39.841"   "184.89.67.60"  "SENT: 334 UGFzc3dvcmQ6"
"SMTPD" 1544    8003    "2013-04-30 12:17:39.888"   "184.89.67.60"  "RECEIVED: ***"
"SMTPD" 1544    8003    "2013-04-30 12:17:39.888"   "184.89.67.60"  "SENT: 235 authenticated."
"SMTPD" 1528    8003    "2013-04-30 12:17:39.919"   "184.89.67.60"  "RECEIVED: MAIL FROM:<sales@mysite.com>"
"SMTPD" 1528    8003    "2013-04-30 12:17:39.919"   "184.89.67.60"  "SENT: 250 OK"
"SMTPD" 1552    8003    "2013-04-30 12:17:39.966"   "184.89.67.60"  "RECEIVED: RCPT TO:<me@mysite.com>"
"SMTPD" 1552    8003    "2013-04-30 12:17:39.966"   "184.89.67.60"  "SENT: 250 OK"
"SMTPD" 1520    8003    "2013-04-30 12:17:39.998"   "184.89.67.60"  "RECEIVED: RCPT TO:<me@mysite.com>"
"SMTPD" 1520    8003    "2013-04-30 12:17:39.998"   "184.89.67.60"  "SENT: 250 OK"
"SMTPD" 1544    8003    "2013-04-30 12:17:40.044"   "184.89.67.60"  "RECEIVED: DATA"
"SMTPD" 1544    8003    "2013-04-30 12:17:40.044"   "184.89.67.60"  "SENT: 354 OK, send."
"SMTPD" 1304    8003    "2013-04-30 12:17:40.123"   "184.89.67.60"  "SENT: 250 Queued (0.078 seconds)"
"SMTPD" 1520    8003    "2013-04-30 12:17:40.169"   "184.89.67.60"  "RECEIVED: QUIT"
"SMTPD" 1520    8003    "2013-04-30 12:17:40.169"   "184.89.67.60"  "SENT: 221 goodbye"

Answer

Maybe you are using an old version?


Answer

How does Ron get the log of results that he uses to figure out that the results weren't right? How do I create a log file while sending multiple emails with one connection like Ron?

Thanks