android - How do I use OAuth 2.0 to send Gmail from Indy? -


The following code successfully sends e-mails through Google's Gmail servers, but only Google Accounts security settings are "less secure apps "

The code below (originally from Remy Levy) does not include OH 2.0, which is necessary if you do not have to make difficult decisions to reduce your security with your users. Ask to allow your application to succeed I can add to the Oath 2.0 Scope of setting satisfy Google's high safety standards?

Work Solution:

  function TTabbedwithNavigationForm.SendEmailNow (FromStr, ToStr, Subject, MessageBody, Host: string; Port: Integer; Username, Pass: String): Boolean; Remy Lebeau with SSL via Gmail Host // Get started with SMTP /// results: = False; Try IdMessage1: = zero; IdSSLIOHandlerSocketOpenSSL1: = Zero; IdSMTP1: = Zero; Try // Setup Mail Message Idmessage1: = TIdMessage.Create (Zero); IdMessage1.From.Address: = FromStr; Change the IDMessage1.Recipients.EmailAddresses: = ToStr in //// League Email; IdMessage1 Subject: = topic; IdMessage1.Body.Text: = MessageBody; // If fileexists (datafile name) then / / idTextment file: = TIdAttachmentFile.Create (IdMessage1.MessageParts, datafilename); Except exception. RaiseOuterException (create exception. ('Could not make message, please try again later')); End; // Setup TLS IdSSLIOHandlerSocketOpenSSL1 Try: = TIdSSLoHandlersocketopenSSL.Create (zero); IdSSLIOHandlerSocketOpenSSL1.SSLOptions.method: = sslvTLSv1; IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Mode: = sslm Inappropriate; IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyMode: [[]; IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyDepth: = 0; Except exception. RaiseOuterException (create exception. (Could not create 'SSL handler, please try again later')); End; // SSL Try / Setup SMTP Try IDSMTP1: = TIdSMTP.Create (Zero); IdSMTP1.IOHandler: = IDSSLohhandlerSocket OpenSSL1; IdSMTP1.UseTLS: = utUseExplicitTLS; IdSMTP1.Host: = Host; // 'smtp.gmail.com'; IdSMTP1.Port: = Port; // 587; IdSMTP1 Username: = Username; // 'username@gmail.com'; IdSMTP1. Pass Word: Pass; // *** Gmail account password '; Except exception. RaiseOuterException (create exception. (Could not make 'SMTP handler, please try again later')); End; // Try Try IdSMTP1.Connect; Try IdSMTP1.Send (IdMessage1); Finally IDSMTP1 Disconnected; End; Except exception. RaiseOuterException (create exception. ('Could not send secure email, please try again later')); End; After all IdSMTP1 free; IdSSLIOHandlerSocketOpenSSL1.Free; IdMessage1.Free; Results: = True; End; Except e: if E.InnerException & lt; & Gt; The exception starts with zero message show ('Error:' + E. Message + # 13 # 13 + E. Innerxation. Message) and Show Message ('Error:' + E. Message); End; End; /// and Remy Lebeau code end;  

You must import the background mail library

  BackgroundMail BM = new background mail (password change activate.); Bm.setGmailUserName (Mail ID); Bm.setGmailPassword (Utils.decryptIt (password)); Bm.setMailTo (OWNEREMAIL); Bm.setFormSubject (subject); Bm.setFormBody (body); Bm.send ();  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -