jkuiper
  • jkuiper
  • 50.75% (Neutral)
  • Newbie Topic Starter
3 years ago
We're using the AESendMail a few years now without problems.
Now gmail is changing their conditions and you can only send mail with OAuth2.
I've test it with the example project and works fine. But in my own project it will not work.
For the user I've created a form to get the accesstoken and refresktoken. This is saved in a database.
Then I create a message and send it to gmail:

procedure Tfo3EmailOpstellen.SendGEmail;
const   ConnectSSLAuto = 1;
var body_html    : string;
begin
    Oauth := TOauthWrapper.Create;
    oSmtp := TMail.Create(nil);
  try
    Oauth.InitGoogleSmtpProvider;
    oSmtp.LicenseCode := 'xxxxxxxx';

    // Set Asynchronous mode
    oSmtp.Asynchronous := 1;

     Oauth.accesstoken  := email.EmailAccountNil.GMail_AccessToken; // from database
     Oauth.refreshtoken := email.EmailAccountNil.GMail_RefreshToken; // from database

     if not DoOauth() then
     begin
       showmessage('Failed to request/refresh access token!');
       exit;
     end;

    oSmtp.Charset := 'utf-8';
    oSmtp.FromAddr := email.EmailAccountNil.SMTP_Inlognaam;
    oSmtp.ReplyTo :=  email.EmailAccountNil.SMTP_Inlognaam;

    // Add recipient's
    oSmtp.ClearRecipient();
    oSmtp.AddRecipientEx(trim(email.EmailAdresNaarOverflow), 0);
    // Set subject
    oSmtp.Subject := email.Onderwerp;

    // Using HTML FORMAT to send mail
    oSmtp.BodyFormat := 1;

    body_html := email.AntwoordHtmlOverflow2;

    oSmtp.ImportHtml( body_html, GetCurrentDir());
    oSmtp.ServerAddr := email.EmailAccountNil.SMTP_Servernaam;
    oSmtp.ServerPort := 587; //ports[lstPort.ItemIndex];
    oSmtp.Protocol := 0; //SMTP protocol

    oSmtp.UserName := Oauth.UserEmail;
    oSmtp.Password := Oauth.AccessToken;
    oSmtp.AuthType := 5; //  XOAUTH2;

    // Use SSL/TLS based on server port.
    oSmtp.ConnectType := ConnectSSLAuto;
    oSmtp.SendMail();

    if oSmtp.GetLastErrDescription() <>'' then
      ShowNBMessage('Fout : ' + oSmtp.GetLastErrDescription())
    else
      ShowNBMessage('Mail verstuurd');
  finally
    Oauth.free;
    oSMTP.free;
  end;

end;
Everytime a mail will be sent, the SMTP will be created. The mail is sent but is not recieved ever. Sendmail() gives no error back.
If I use this piece of code with geeting an accesscode the mail is sent and received succesfully. But then I have to login to gmail everytime when sending mail.

Is it possible to send a mail with a accesskey without logged in gmail?

I created my project in Delphi 10.4


with kind regards,
John Kuiper.
ivan
  • ivan
  • 100% (Exalted)
  • Administration
3 years ago
Hi, you used asynchronous mode, you cannot get the result directly from the GetLastErrDescription like this way.

Please refer to the sample project in EASendMail, you should use OnError event to catch the error information.

https://www.emailarchitect.net/easendmail/kb/delphi.aspx?cat=11 
rkamp2
  • rkamp2
  • 50.75% (Neutral)
  • Newbie
3 years ago
Hi,

Did you every resolve your problem? I just started your a relay service for the customer. Gmail is getting worst and worst to deal with.

Thanks,

Rick Kamp
ivan
  • ivan
  • 100% (Exalted)
  • Administration
3 years ago

Hi,

Did you every resolve your problem? I just started your a relay service for the customer. Gmail is getting worst and worst to deal with.

Thanks,

Rick Kamp

Originally Posted by: rkamp2 



If you have any problem, please contact our technical support email address directly:

https://www.emailarchitect.net/contact.aspx 

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.