Java Code Examples for javax.mail.internet.InternetAddress#setPersonal()
The following examples show how to use
javax.mail.internet.InternetAddress#setPersonal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MailService.java From ml-blog with MIT License | 6 votes |
@Async public void sendEmail(String toEmail,String subject, String content) throws Exception { Context con = new Context(); con.setVariable("content", content); String emailtext = templateEngine.process("portal/mail.html", con); MimeMessage message = this.javaMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8"); InternetAddress from = new InternetAddress(); from.setAddress(this.mailProperties.getUsername()); from.setPersonal(commonMap.get("blogName").toString(), "UTF-8"); helper.setFrom(from); helper.setTo(toEmail); helper.setSubject(subject); helper.setText(emailtext, true); this.javaMailSender.send(message); log.info("发送邮件内容:{}",content); }
Example 2
Source File: EmailInfoServiceImpl.java From roncoo-adminlte-springmvc with Apache License 2.0 | 6 votes |
public void send(String fromUser, String to, String subject, String text) { try { MimeMessage message = javaMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8"); InternetAddress from = new InternetAddress(); from.setAddress(fromUser); from.setPersonal(NAME, "UTF-8"); helper.setFrom(from); helper.setTo(to); helper.setSubject(subject); helper.setText(text, true); javaMailSender.send(message); } catch (Exception e) { e.printStackTrace(); } }
Example 3
Source File: MessageHelper.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private Address[] getAddressHeader(String name) throws MessagingException { ensureMessage(false); String header = imessage.getHeader(name, ","); if (header == null) return null; header = fixEncoding(name, header); header = header.replaceAll("\\?=[\\r\\n\\t ]+=\\?", "\\?==\\?"); Address[] addresses = InternetAddress.parseHeader(header, false); for (Address address : addresses) { InternetAddress iaddress = (InternetAddress) address; String email = iaddress.getAddress(); String personal = iaddress.getPersonal(); email = decodeMime(email); if (!Helper.isSingleScript(email)) email = punyCode(email); iaddress.setAddress(email); if (personal != null) { try { iaddress.setPersonal(decodeMime(personal)); } catch (UnsupportedEncodingException ex) { Log.w(ex); } } } return addresses; }
Example 4
Source File: MimePackage.java From ats-framework with Apache License 2.0 | 5 votes |
/** * Set the sender (From header) for the package * * @param sender * the sender email address * @throws PackageException */ @PublicAtsApi public void setSender( String sender ) throws PackageException { String newSenderAddress; String newSenderPersonal; try { InternetAddress address = new InternetAddress(); sender = sender.replaceAll("[<>]", "").trim(); boolean hasPersonal = sender.contains(" "); if (hasPersonal) { newSenderAddress = sender.substring(sender.lastIndexOf(' ')); newSenderPersonal = sender.substring(0, sender.lastIndexOf(' ')); address.setPersonal(newSenderPersonal.trim()); } else { newSenderAddress = sender; } // set the sender address address.setAddress(newSenderAddress.trim()); message.setFrom(address); } catch (ArrayIndexOutOfBoundsException aioobe) { throw new PackageException("Sender not present"); } catch (MessagingException me) { throw new PackageException(me); } catch (UnsupportedEncodingException uee) { throw new PackageException("Error setting address personal", uee); } }
Example 5
Source File: MimePackage.java From ats-framework with Apache License 2.0 | 5 votes |
/** * Set the sender display name on the From header * * @param name * the display name to set * @throws PackageException */ @PublicAtsApi public void setSenderName( String name ) throws PackageException { try { InternetAddress address = new InternetAddress(); String[] fromHeaders = getHeaderValues(FROM_HEADER); if (fromHeaders != null && fromHeaders.length > 0) { // parse the from header if such exists String fromHeader = fromHeaders[0]; if (fromHeader != null) { address = InternetAddress.parse(fromHeader)[0]; } } address.setPersonal(name); message.setFrom(address); } catch (ArrayIndexOutOfBoundsException aioobe) { throw new PackageException("Sender not present"); } catch (MessagingException me) { throw new PackageException(me); } catch (UnsupportedEncodingException uee) { throw new PackageException(uee); } }
Example 6
Source File: EmailMessageSender.java From studio with GNU General Public License v3.0 | 5 votes |
protected boolean sendEmail(final String subject, final String content, final String userEmailAddress, final String replyTo, final String personalFromName) { boolean success = true; MimeMessagePreparator preparator = new MimeMessagePreparator() { public void prepare(MimeMessage mimeMessage) throws Exception { mimeMessage.addRecipients(Message.RecipientType.TO, InternetAddress.parse(userEmailAddress)); InternetAddress[] replyTos = new InternetAddress[1]; if ((replyTo != null) && (!"".equals(replyTo))) { replyTos[0] = new InternetAddress(replyTo); mimeMessage.setReplyTo(replyTos); } InternetAddress fromAddress = new InternetAddress(getDefaultFromAddress()); if (personalFromName != null) fromAddress.setPersonal(personalFromName); mimeMessage.setFrom(fromAddress); mimeMessage.setContent(content, "text/html; charset=utf-8"); mimeMessage.setSubject(subject); logger.debug("sending email to [" + userEmailAddress + "]subject subject :[" + subject + "]"); } }; try { if (isAuthenticatedSMTP()) { emailService.send(preparator); } else { emailServiceNoAuth.send(preparator); } } catch (MailException ex) { // simply log it and go on... logger.error("Error sending email notification to:" + userEmailAddress, ex); success = false; } return success; }