West Wind Client Tools
Re: Sending email
You need to set nMailMode=0 to get .NET mode which supports TLS to work.
DO wwSmtp LOCAL loSmtp as wwSmtp loSmtp = CREATEOBJECT("wwSmtp") loSmtp.nMailMode = 0 && .NET
+++ Rick ---
Hello,
We have been using old wwUtils for a long time for emailing. Now that it doesn't support SSL/TLS we decided to replace it. I was going to write a .Net COM for it but then noticed that it says new version supports SSL/TLS. I downloaded it today and testing but having a hard time to make it work. Help!
Here is the code that I try (almost the exact copy of sample in help):
DO wwSmtp LOCAL loSmtp as wwSmtp loSmtp = CREATEOBJECT("wwSmtp") *loSmtp.cMailServer = "Localhost" loSmtp.cMailServer = "smtp.gmail.com:587" *loSmtp.nSERVERPORT = 587 loSmtp.lUseSsl = .T. && Google requires TLS *** Optional authentication if server requires it loSmtp.cUsername = "cetinbasoz" loSmtp.cPassword = "secret" loSmtp.cSenderName= "Cetin Basoz" loSmtp.cSenderEmail = "cetinbasoz@gmail.com" loSmtp.cRecipient = "cetin@accutrack.org" loSmtp.cCcList = "cetin@engineerica.com" *** Optional - custom content type - text/plain by default loSmtp.cContentType = "text/html" loSmtp.cSubject = "Test Message through Google" loSmtp.cMessage = "<b>Test message from wwsmtp, to check out how this operation works.</b>" *** Optional - a couple of options loSmtp.cReplyTo = "cetinbasoz@gmail.com" *** Send it llResult = loSmtp.Sendmail() IF llResult WAIT WINDOW "Mail sent..." nowait ELSE ? "Mail sending failed: " ? loSmtp.cErrorMsg ENDIF
(Of course instead of secret I have my password there)
It always returns:
<b>Must issue a STARTTLS command first</b>
If I try SendMailAsynch() it doesn't error but nothing sent as well.
However this code just works from .Net:
void Main() { SendSimple(); } private void SendSimple() { MailMessage message = new MailMessage(); message.From = new MailAddress("cetinbasoz@gmail.com"); message.To.Add(new MailAddress("cetin.basoz@deu.edu.tr")); message.Bcc.Add(new MailAddress("cetin@accutrack.org","Cetin At AccuTrack")); message.Subject = "Test Message through Google"; message.Body = "<b>Test message from .Net, to check out how this operation works.</b>"; message.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host="smtp.gmail.com"; smtp.Port=587; smtp.Credentials = new NetworkCredential("cetinbasoz@gmail.com", "secret"); smtp.EnableSsl = true; object userState = message; // UserState parameter can be anything smtp.SendCompleted += (s, e) => { //Get the Original MailMessage object MailMessage mail= (MailMessage)e.UserState; if (e.Cancelled) { Console.WriteLine("Send canceled for mail with subject [{0}].", mail.Subject); } if (e.Error != null) { Console.WriteLine("Error {1} occurred when sending mail [{0}] ", mail.Subject, e.Error.ToString()); } else { Console.WriteLine("Message [{0}] sent.", mail.Subject ); } }; smtp.SendAsync( message, userState ); }
Where do I go wrong? Or does it really support TLS/SSL?
TIA
Rick Strahl
West Wind Technologies
Making waves on the Web
West Wind Technologies
Making waves on the Web
from Hood River, Oregon