From a1ec223a7ee9ff86a881428f787c6f11d532432a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 12 Jul 2022 20:13:45 -0700 Subject: Support from email name (fix #4887) --- src/main/java/org/traccar/database/MailManager.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/database/MailManager.java b/src/main/java/org/traccar/database/MailManager.java index 0c868e1fc..72b8b72c1 100644 --- a/src/main/java/org/traccar/database/MailManager.java +++ b/src/main/java/org/traccar/database/MailManager.java @@ -31,6 +31,7 @@ import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; +import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.Properties; @@ -88,6 +89,10 @@ public final class MailManager { if (from != null) { properties.put("mail.smtp.from", from); } + String fromName = provider.getString("mail.smtp.fromName"); + if (fromName != null) { + properties.put("mail.smtp.fromName", fromName); + } } return properties; } @@ -120,7 +125,16 @@ public final class MailManager { String from = properties.getProperty("mail.smtp.from"); if (from != null) { - message.setFrom(new InternetAddress(from)); + String fromName = properties.getProperty("mail.smtp.fromName"); + if (fromName != null) { + try { + message.setFrom(new InternetAddress(from, fromName)); + } catch (UnsupportedEncodingException e) { + throw new MessagingException("Email address issue"); + } + } else { + message.setFrom(new InternetAddress(from)); + } } message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail())); -- cgit v1.2.3