java - cannot send email using gmail account from android using javax -


error sending email:

returns 451 4.5.0 smtp protocol violation, see rfc 2821 g5sm13340466pfg.0 - gsmtp.

after getting oauth token, type , oauth expire gmail.

here following code used test send email using oauth2.

private string generateoauth2string(boolean base64_encode){         string oauthstring = "";         log.e("sendtestactivity", "authtoken: " + authtoken);         oauthstring = string.format("user=%s\1auth=bearer %s\1\1", username, authtoken);         log.e("sendtestactivity", "non base 64: " + oauthstring);         if (base64_encode)             oauthstring = base64.encodetostring(oauthstring.getbytes(), base64.default);         log.e("sendtestactivity", "base 64: " + oauthstring);         return oauthstring;     }      private synchronized void sendmail(string subject, string body, string user, string recipients) {         try {                        properties props = new properties();             props.put("mail.smtp.starttls.enable", "true");             props.put("mail.smtp.starttls.required", "true");             props.put("mail.smtp.sasl.enable", "false");              session = session.getinstance(props);             session.setdebug(true);              final urlname unusedurlname = null;             smtptransport transport = new smtptransport(session, unusedurlname);             // if password non-null, smtp tries auth login.             final string emptypassword = null;             transport.connect("smtp.gmail.com", 587, user, emptypassword);              transport.issuecommand("auth xoauth2 " + generateoauth2string(true),                     235);              mimemessage message = new mimemessage(session);              // set from: header field of header.              message.setfrom(new internetaddress(user));               // set to: header field of header.              message.addrecipient(message.recipienttype.to, new internetaddress(recipients));               // set subject: header field              message.setsubject(subject);               // set actual message              message.settext(body);              if (recipients.indexof(',') > 0)                    message.setrecipients(message.recipienttype.to, internetaddress.parse(recipients));                else                   message.setrecipient(message.recipienttype.to, new internetaddress(recipients));                 transport.send(message);              log.e("sendtestactivity", "email sent");          } catch (exception e) {             log.e("sendtestactivity", e.getmessage());         }      } 

is there wrong setup?

also \1 in user=%s\1auth=bearer %s\1\1 "string" or "start of heading" character

you're doing hard way. let javamail you.


Comments