EldoS | Feel safer!

Software components for data protection, secure storage and transfer

gmail send mail problemm

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#12986
Posted: 04/12/2010 12:00:25
by Levan Sopromadze (Basic support level)
Joined: 02/16/2010
Posts: 5

Hi all, I wrote application to send emails. I used smtpClient to do this, It's working, but if I changed email with gmail smtp settings, I can't send mail.
I tried to use 465 port instead of 25, but without result.
This is my code:
Code

public string mailHost = "smtp.gmail.com";
public string mailUser = "***********@googlemail.com";
public string mailPass = "**********";

...

SBUtils.Unit.SetLicenseKey(licenseKey);

            SBSimpleMIME.TElSimpleMIMEMessage mailMessage = new SBSimpleMIME.TElSimpleMIMEMessage();
            SBSMTPClient.TElSMTPClient smtpClient = new SBSMTPClient.TElSMTPClient();
            SBSimpleMIME.TElSimpleMIMEAttachment attachement = new SBSimpleMIME.TElSimpleMIMEAttachment();

            smtpClient.Address = mailHost;
            smtpClient.Username = mailUser;
            smtpClient.Password = mailPass;            
            smtpClient.Port = 465;
            //smtpClient.Port = 25;

            mailMessage.Subject = mailSubj;
            mailMessage.From = mailFrom;
            mailMessage.To_.Add(mailTo);
            mailMessage.BodyPlain.Text = mailText;

            // Adding attachment
            int idx = mailMessage.AddAttachment();
            if (idx != -1)
            {
                attachement = mailMessage.get_Attachments(idx);
                attachement.ContentStream = new FileStream(filename, FileMode.Open);
                attachement.ContentType = "image/bmp";
                attachement.Name = mailAttachName;
            }

            try
            {
                smtpClient.Open();
                smtpClient.Login("");
                smtpClient.Send(mailMessage);
                //smtpClient.OnSent();
        
                Result("Sent Successfuly");
            }
            catch (Exception ex)
            {
              ....
            }
            finally
            {
                smtpClient.Close(true);
                attachement.Dispose();
                mailMessage.Dispose();
            }


Please help me if you can...
#12987
Posted: 04/12/2010 12:19:33
by Eugene Mayevski (EldoS Corp.)

Port 465 expects implicit TLS and I don't see that you have enabled it for smtpClient in your code.


Sincerely yours
Eugene Mayevski
#12989
Posted: 04/12/2010 12:39:24
by Levan Sopromadze (Basic support level)
Joined: 02/16/2010
Posts: 5

I changed my code:
Code
smtpClient.Address = mailHost;
            smtpClient.Username = mailUser;
            smtpClient.Password = mailPass;
            smtpClient.UseSSL = true;
            smtpClient.Port = 465;
            smtpClient.SSLMode = SBSMTPClient.TSBSSLMode.smImplicit;
            smtpClient.UseInternalSocket = true;            


But I got error: "Certificate validation handler is not assigned".
I found this at forum:
Code
smtpClient.OnCertificateValidate += new SBSSLCommon.TSBCertificateValidateEvent(client_OnCertificateValidate);
smtpClient.OnError += new SBSSLCommon.TSBErrorEvent(client_OnError);


But I can't understood how "client_OnCertificateValidate" works and how I can use it, maybe you can explain me ?
Thanks...
#12994
Posted: 04/12/2010 23:20:17
by Ken Ivanov (EldoS Corp.)

Certificate validation basics are are explained here. You can also use TElX509CertificateValidator component that will do most of the work explained there for you.

Reply

Statistics

Topic viewed 1282 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!