Archived Forum PostQuestion:
Hello.
I have a license for both the ActiveX and for the .NET version of Chilkat.
For both I'm using exactely the same ChilkatMail properties. With VB6, it works fine, but the same code fails in VB.NET in the function "VerifySMTPConnection".
Here is the LastError log for VB6:
* VerifySMTPConnection:1
ChilkatLog:
VerifySmtpConnection:
DllDate: Jun 10 2014
ChilkatVersion: 9.5.0.40
UnlockPrefix: MYCHILKATUNLOCKKEY
Username: MYUSER-PC:MyUser
Architecture: Little Endian; 32-bit
Language: ActiveX
VerboseLogging: 0
Checking TCP/IP connectivity to the SMTP server.
This does not check the login/password.
AutoFix: SMTP port 465 is typically for implicit SSL/TLS.
To prevent auto-fix, set the AutoFix property = False/0
Checking connectivity to SMTP server smtp.gmail.com:465
smtp_host: smtp.gmail.com
smtp_port: 465
socket2Connect:
connect2:
connectImplicitSsl:
checkServerCert:
Not verifying server certificate...
Set the RequireSslCertVerify property to enable verification.
--checkServerCert
Secure Channel Established.
--connectImplicitSsl
--connect2
--socket2Connect
SmtpCmdResp: 220 smtp.gmail.com ESMTP 5sm543244wrb.9 - gsmtp
ESMTP server smtp.gmail.com:465 is reachable
checkSmtpConnection: Elapsed time: 234 millisec
Success.
--VerifySmtpConnection
--ChilkatLog
And this is the log for VB.NET:
* VerifySMTPConnection:False
ChilkatLog:
VerifySmtpConnection:
DllDate: Aug 30 2017
ChilkatVersion: 9.5.0.69
UnlockPrefix: MYCHILKATUNLOCKKEY
Architecture: Little Endian; 32-bit
Language: .NET 4.6
VerboseLogging: 0
AutoFix: SMTP port 465 is typically for implicit SSL/TLS.
To prevent auto-fix, set the AutoFix property = False/0
smtpConnectAndAuthenticate:
smtpConnect:
smtpHostname: smtp.gmail.com
smtpPort: 465
connectionIsReady:
Need new SMTP connection
--connectionIsReady
smtpSocketConnect:
socketOptions:
SO_SNDBUF: 262144
SO_RCVBUF: 4194304
TCP_NODELAY: 1
SO_KEEPALIVE: 1
--socketOptions
--smtpSocketConnect
smtpGreeting:
readSmtpResponse:
SmtpCmdResp: 220 smtp.gmail.com ESMTP t37sm617192wrc.28 - gsmtp
--readSmtpResponse
--smtpGreeting
startTLS:
sendCmdToSmtp:
SmtpCmdSent: EHLO MYUSER-PC<crlf>
--sendCmdToSmtp
readSmtpResponse:
SmtpCmdResp: 250-smtp.gmail.com at your service, [178.203.233.193]
SmtpCmdResp: 250-SIZE 35882577
SmtpCmdResp: 250-8BITMIME
SmtpCmdResp: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
SmtpCmdResp: 250-ENHANCEDSTATUSCODES
SmtpCmdResp: 250-PIPELINING
SmtpCmdResp: 250-CHUNKING
SmtpCmdResp: 250 SMTPUTF8
--readSmtpResponse
sendCmdToSmtp:
SmtpCmdSent: STARTTLS<crlf>
--sendCmdToSmtp
readSmtpResponse:
SmtpCmdResp: 530-5.5.1 Authentication Required. Learn more at
SmtpCmdResp: 530 5.5.1 https://support.google.com/mail/?p=WantAuthError t37sm617192wrc.28 - gsmtp
--readSmtpResponse
Non-success STARTTLS response.
--startTLS
--smtpConnect
--smtpConnectAndAuthenticate
Failed.
--VerifySmtpConnection
--ChilkatLog
What am I doing wrong here?
I'm also attaching my code.
This is the VB6 code:
Option Explicit
Private Sub Form_Load()
Dim ch As New Chilkat_v9_5_0.ChilkatMailMan
ch.UnlockComponent m_sUnlockKey
ch.AutoFix = 1
ch.MailHost = "pop.gmail.com"
ch.MailPort = 995
ch.PopUsername = m_sUserName
ch.PopPassword = m_sPass
ch.SmtpHost = "smtp.gmail.com"
ch.SmtpPassword = m_sPass
ch.SmtpUsername = m_sUserName
ch.SmtpPort = 465
ch.SmtpAuthMethod = ""
ch.PopSsl = 1
ch.Pop3SPA = 0
ch.StartTLS = 1
ch.SmtpSsl = 1
Debug.Print "mailhost: " & ch.MailHost
Debug.Print "mailport: " & ch.MailPort
Debug.Print "popusername: " & ch.PopUsername
Debug.Print "poppassword: " & ch.PopPassword
Debug.Print "smtphost: " & ch.SmtpHost
Debug.Print "smtppassword: " & ch.SmtpPassword
Debug.Print "smtpusername: " & ch.SmtpUsername
Debug.Print "smtpport: " & ch.SmtpPort
Debug.Print "smtphost: " & ch.SmtpHost
Debug.Print "smtpauthmethod: " & ch.SmtpAuthMethod
Debug.Print "popssl: " & ch.PopSsl
Debug.Print "pop3spa: " & ch.Pop3SPA
Debug.Print "starttls: " & ch.StartTLS
Debug.Print "smtpssl : " & ch.SmtpSsl
Dim bVerifyPopConnection As Boolean
Dim bVerifyPopLogin As Boolean
Dim bVerifySmtpConnection As Boolean
Dim bVerifySmtpLogin As Boolean
Dim sErrVerifyPopConnection$
Dim sErrVerifyPopLogin$
Dim sErrVerifySmtpConnection$
Dim sErrVerifySmtpLogin$
Dim m_sMailReport$
m_sMailReport = ""
'Test incoming
Dim lRetInCon&
Dim sRetInCon$
lRetInCon = ch.VerifyPopConnection
sRetInCon = ch.LastErrorText
bVerifyPopConnection = CBool(lRetInCon)
m_sMailReport = m_sMailReport & "* VerifyPopConnection:" & lRetInCon & vbNewLine & pCleanMailReport(sRetInCon) & vbNewLine & vbNewLine
Dim lRetInLogin&
Dim sRetInLogin$
lRetInLogin = ch.VerifyPopLogin
sRetInLogin = ch.LastErrorText
bVerifyPopLogin = CBool(lRetInLogin)
m_sMailReport = m_sMailReport & "* VerifyPopLogin: " & lRetInLogin & vbNewLine & pCleanMailReport(sRetInLogin) & vbNewLine & vbNewLine
'Test outgoing
Dim lRetOutCon&
Dim sRetOutCon$
lRetOutCon = ch.VerifySmtpConnection
sRetOutCon = ch.LastErrorText
bVerifySmtpConnection = CBool(lRetOutCon)
m_sMailReport = m_sMailReport & "* VerifySMTPConnection:" & lRetOutCon & vbNewLine & pCleanMailReport(sRetOutCon) & vbNewLine & vbNewLine
Dim lRetOutLogin&
Dim sRetOutLogin$
lRetOutLogin = ch.VerifySmtpLogin
sRetOutLogin = ch.LastErrorText
bVerifySmtpLogin = CBool(lRetOutLogin)
m_sMailReport = m_sMailReport & "* VerifySMTPLogin:" & lRetOutLogin & vbNewLine & pCleanMailReport(sRetOutLogin) & vbNewLine & vbNewLine
Debug.Print m_sMailReport
End Sub
Private Function pCleanMailReport(ByVal value As String) As String
Dim s As String
s = value
s = Replace(s, m_sUserName, "<MYUSERNAME>")
s = Replace(s, m_sPass, "<MYPASSWORD>")
s = Replace(s, m_sUnlockKey, "MYCHILKATUNLOCKKEY")
pCleanMailReport = s
End Function
And this is my VB.NET code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim ch As New Chilkat.MailMan
ch.UnlockComponent(_sUnlockKey)
ch.AutoFix = True
ch.MailHost = "pop.gmail.com"
ch.MailPort = 995
ch.PopUsername = _sUserName
ch.PopPassword = _sPass
ch.SmtpHost = "smtp.gmail.com"
ch.SmtpPassword = _sPass
ch.SmtpUsername = _sUserName
ch.SmtpPort = 465
ch.SmtpAuthMethod = ""
ch.PopSsl = True
ch.Pop3SPA = False
ch.StartTLS = True
ch.SmtpSsl = True
Debug.Print("mailhost: " & ch.MailHost)
Debug.Print("mailport: " & ch.MailPort)
Debug.Print("popusername: " & ch.PopUsername)
Debug.Print("poppassword: " & ch.PopPassword)
Debug.Print("smtphost: " & ch.SmtpHost)
Debug.Print("smtppassword: " & ch.SmtpPassword)
Debug.Print("smtpusername: " & ch.SmtpUsername)
Debug.Print("smtpport: " & ch.SmtpPort)
Debug.Print("smtphost: " & ch.SmtpHost)
Debug.Print("smtpauthmethod: " & ch.SmtpAuthMethod)
Debug.Print("popssl: " & ch.PopSsl)
Debug.Print("pop3spa: " & ch.Pop3SPA)
Debug.Print("starttls: " & ch.StartTLS)
Debug.Print("smtpssl : " & ch.SmtpSsl)
Dim _sMailReport As String = String.Empty
'Test incoming
Dim bRetInCon As Boolean = ch.VerifyPopConnection()
Dim sRetInCon As String = ch.LastErrorText
_sMailReport = _sMailReport & "* VerifyPopConnection:" & CStr(bRetInCon) & Environment.NewLine & pCleanMailReport(sRetInCon) & Environment.NewLine & Environment.NewLine
Dim bRetInLogin As Boolean = ch.VerifyPopLogin()
Dim sRetInLogin As String = ch.LastErrorText
_sMailReport = _sMailReport & "* VerifyPopLogin: " & CStr(bRetInLogin) & Environment.NewLine & pCleanMailReport(sRetInLogin) & Environment.NewLine & Environment.NewLine
'Test outgoing
Dim bRetOutCon As Boolean = ch.VerifySmtpConnection()
Dim sRetOutCon As String = ch.LastErrorText
_sMailReport = _sMailReport & "* VerifySMTPConnection:" & CStr(bRetOutCon) & Environment.NewLine & pCleanMailReport(sRetOutCon) & Environment.NewLine & Environment.NewLine
Dim bRetOutLogin As Boolean = ch.VerifySmtpLogin()
Dim sRetOutLogin As String = ch.LastErrorText
_sMailReport = _sMailReport & "* VerifySMTPLogin:" & CStr(bRetOutLogin) & Environment.NewLine & pCleanMailReport(sRetOutLogin) & Environment.NewLine & Environment.NewLine
Debug.Print(_sMailReport)
End Sub
Private Function pCleanMailReport(ByVal value As String) As String
Dim s As String = value
s = Replace(s, _sUserName, "<MYUSERNAME>")
s = Replace(s, _sPass, "<MYPASSWORD>")
s = Replace(s, _sUnlockKey, "MYCHILKATUNLOCKKEY")
Return s
End Function
End Class
The debug messages (Debug.Print("mailhost: " & ch.MailHost), etc.) show me that all properties of the ChilkatMail are set to the same in VB6 and in VB.NET.
The strange thing is that - although VerifySMTPConnection fails - sending a mail in VB.NET works with this sample:
https://www.example-code.com/vbdotnet/smtp_gmailSsl.asp
So maybe it's a bug in the ChilkatDotNet because in VB6 "VerifySMTPConnection" works just perfectly.
Doesn't anybody else have this problem?
What I've noticed is that in the VB6 example, after setting STARTTLS to TRUE, it stays TRUE. In the VB.NET example, I set it to TRUE as well, but it keeps staying FALSE.
Hmmm, I just noticed that even on VB6, VerifySMTP connection doesn't succeed.
I'll check further first.
Ok, I now found out that if I just run the line
Dim bVerifySmtpConnection As Boolean = ch.VerifySmtpConnection()
or (for VB6):
lRetOutCon = ch.VerifySmtpConnection
twice, the first attempt will fail while the second one will succeed.
What might cause this?