Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
jkuiper  
#1 Posted : Friday, May 6, 2022 9:57:17 AM(UTC)
jkuiper

Rank: Newbie

Groups: Registered
Joined: 5/6/2022(UTC)
Posts: 1
Netherlands
Location: Zaandam

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:
Code:

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  
#2 Posted : Friday, May 13, 2022 12:27:18 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
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.emailarchite...il/kb/delphi.aspx?cat=11
rkamp2  
#3 Posted : Monday, July 25, 2022 2:48:25 PM(UTC)
rkamp2

Rank: Newbie

Groups: Registered
Joined: 4/19/2020(UTC)
Posts: 1
United States
Location: San Jose, CA

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  
#4 Posted : Monday, July 25, 2022 4:04:35 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Originally Posted by: rkamp2 Go to Quoted Post
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


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

https://www.emailarchitect.net/contact.aspx
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.061 seconds.

EXPLORE TUTORIALS

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