Google OAuth 2.0 を使用して、Gmail を使用しているユーザーに代わってメールを送信しています。SMTP プロトコルを使用します。これが私のコードです:
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 = Session.getInstance(props);
session.setDebug(false);
final URLName unusedUrlName = null;
SMTPTransport transport = new SMTPTransport(session, unusedUrlName);
transport.connect("smtp.gmail.com", 587, fromAddress, null);
byte[] response = String.format("user=%s\1auth=Bearer %s\1\1", lFrom, oauthToken).getBytes();
response = BASE64EncoderStream.encode(response);
transport.issueCommand("AUTH XOAUTH2 " + new String(response),
235);
MimeMessage msg = new MimeMessage( session );
msg.setFrom( new InternetAddress( fromAddress , fromName ) );
msg.setRecipients( Message.RecipientType.TO , InternetAddress.parse( toAddress , false ) );
msg.setSubject( emailSubject );
MimeBodyPart htmlPart = new MimeBodyPart();
Multipart multiPart = new MimeMultipart();
htmlPart.setContent( "<html>email content</html>" , "text/html; charset=UTF-8" );
multiPart.addBodyPart( htmlPart );
msg.setContent( multiPart );
msg.saveChanges();
transport.sendMessage(msg, msg.getAllRecipients());
当社のソフトウェアは、Google App Engine プラットフォームでホストされています。上記の方法を使用して送信された電子メールには、値が「base64」の Content-Transfer-Encoding ヘッダーが常に含まれています。
gmail.com を使用して送信される通常のメールは、このようにエンコードされません。回避策はありますか?それとも、これは常に期待されていることですか? すべてのメール サービス プロバイダー (プライベート サーバーを含む) がサポートしていますか? 私はこれについてほとんど知りません。ありがとう。