Base64: java.lang.IllegalArgumentException: Illegal character

Your encoded text is [B@6499375d. That is not Base64, something went wrong while encoding. That decoding code looks good. Use this code to convert the byte[] to a String before adding it to the URL: String encodedEmailString = new String(encodedEmail, “UTF-8”); // … String confirmLink = “Complete your registration by clicking on following” + “\n<a … Read more

Javamail api in android using XOauth

I researched this for some days and I found a solution that is working for me at the moment. I get the oauth2 token from the android AccountManager and then send the email via SMTP using JavaMail. The idea is based on the Java example here http://code.google.com/p/google-mail-oauth2-tools/wiki/JavaSampleCode and on this java Xoauth example here http://google-mail-xoauth-tools.googlecode.com/svn/trunk/java/com/google/code/samples/xoauth/XoauthAuthenticator.java … Read more

Using JavaMail with TLS

We actually have some notification code in our product that uses TLS to send mail if it is available. You will need to set the Java Mail properties. You only need the TLS one but you might need SSL if your SMTP server uses SSL. Properties props = new Properties(); props.put(“mail.smtp.starttls.enable”,”true”); props.put(“mail.smtp.auth”, “true”); // If … Read more

Download attachments using Java Mail

Without exception handling, but here goes: List<File> attachments = new ArrayList<File>(); for (Message message : temp) { Multipart multipart = (Multipart) message.getContent(); for (int i = 0; i < multipart.getCount(); i++) { BodyPart bodyPart = multipart.getBodyPart(i); if(!Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition()) && StringUtils.isBlank(bodyPart.getFileName())) { continue; // dealing with attachments only } InputStream is = bodyPart.getInputStream(); // — EDIT — … Read more

Postfix and OpenJDK 11: “No appropriate protocol (protocol is disabled or cipher suites are inappropriate)”

I was facing the same issue using JDK 11. But I resolved it by commenting this line in the java.security file: jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, include jdk.disabled.namedCurves

How to read text inside body of mail using javax.mail

This answer extends yurin’s answer. The issue he brought up was that the content of a MimeMultipart may itself be another MimeMultipart. The getTextFromMimeMultipart() method below recurses in such cases on the content until the message body has been fully parsed. private String getTextFromMessage(Message message) throws MessagingException, IOException { String result = “”; if (message.isMimeType(“text/plain”)) … Read more

UTF-8 charset doesn’t work with javax.mail

For all e-mails There are a couple of system properties related to mailing, that can probably simplify your code. I am talking about this specific property actually: “mail.mime.charset”. The mail.mime.charset System property can be used to specify the default MIME charset to use for encoded words and text parts that don’t otherwise specify a charset. … Read more