mm.addTo(x.getAddress()); } catch (EmailException e) { throw new ProcessException("Failed to add TO recipient.", e);
/** * 发送多媒体邮件,可以携带附件信息 * @param urls 附件的URL,key为附件的名称 */ public void sendMultipartEmail(String targetAddress,String title,String content,Map<String,URL> urls) throws Exception { MultiPartEmail email = new MultiPartEmail(); for(Map.Entry<String,URL> entry : urls.entrySet()) { email.attach(entry.getValue(),entry.getKey(),EmailAttachment.ATTACHMENT); } email.setSubject(title); email.addTo(targetAddress); email.setMsg(content); sendEmail(email); }
userMail.attach(attachment, name, desc); userMail.addTo(report.getUserEmail()); LoggerFactory.getLogger(this.getClass()).info("Sending error report to User: " + report.getUserEmail()); Mail.send(userMail); reportMail.addTo(REPORT_ADRESS); if (attachment != null) reportMail.attach(attachment, name, desc);
public static boolean sendEmail(String [] mailTo, String mailFrom, String msgSubject, String msgContent) { MultiPartEmail multMail = new MultiPartEmail(); // SMTP multMail.setHostName(mailHost); multMail.setSmtpPort(smtpPort); // 需要提供公用的邮件用户名和密码 multMail.setAuthentication( mailUser, mailPassword); try { //multMail.setFrom(CodeRepositoryUtil.getValue("SysMail", "admin_email")); multMail.setFrom(mailFrom); multMail.addTo(mailTo); multMail.setSubject(msgSubject); msgContent = msgContent.trim(); if(msgContent.endsWith("</html>") || msgContent.endsWith("</HTML>")){ multMail.addPart(msgContent, "text/html;charset=utf-8"); }else{ multMail.setMsg(msgContent); } multMail.send(); return true; } catch (EmailException e) { logger.error(e.getMessage(),e);//e.printStackTrace(); } return false; }
while (it.hasNext()) { String key = (String) it.next(); email.addTo((String) toEmails.get(key), key);
while (it.hasNext()) { String key = (String) it.next(); email.addTo((String) toEmails.get(key), key);
email.setFrom(SandraSchedulerConfigHelper.getSandraEmailForm(config)); for (String recipient : to) { email.addTo(recipient);
email.setFrom(SandraSchedulerConfigHelper.getSandraEmailForm(config)); for (String recipient : to) { email.addTo(recipient);
email.setHostName(hostName); email.setSmtpPort(Integer.parseInt(smtpPort)); email.addTo(toEmail, toName); email.setFrom(sender_Mail, sender_Name); email.setSubject(subject);
email.addTo(emailTo, "Support");
MultiPartEmail email = new MultiPartEmail(); email.setHostName(smtpServer); email.addTo(to); email.setFrom(from); email.setSubject(subject); email.setMsg(msg); email.setSocketTimeout(20000); email.setSocketConnectionTimeout(20000); // SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); // soapMessage.createAttachmentPart(); // enough for empty body new AttachmentPartImpl(); // enough for empty body // new MimeHeaders(); not enough for empty body email.send();
email.setHostName(hostName); email.setSmtpPort(Integer.parseInt(smtpPort)); email.addTo(toEmail, toName); email.setFrom(sender_Mail, sender_Name); email.setSubject(subject);
public String sendEmailMessage(String mailTo,String mailFrom,String msgSubject,String msgContent) { MultiPartEmail multMail = new MultiPartEmail(); // SMTP multMail.setHostName(hostName); //CodeRepositoryUtil.getValue("SysMail", "host_name")); multMail.setSmtpPort(smtpPort); String resStr = "OK"; // 需要提供公用的消息用户名和密码 multMail.setAuthentication(userName, userPassword); //CodeRepositoryUtil.getValue("SysMail", "host_user"), //CodeRepositoryUtil.getValue("SysMail", "host_password")); try { //multMail.setFrom(CodeRepositoryUtil.getValue("SysMail", "admin_email")); multMail.setFrom(mailFrom); multMail.addTo(mailTo); multMail.setSubject(msgSubject); multMail.setMsg(msgContent); multMail.send(); return "OK"; } catch (EmailException e) { resStr=e.getMessage(); logger.error(e.getMessage(),e); //e.printStackTrace(); } return resStr; }
public static boolean sendEmail(String [] mailTo, String mailFrom, String msgSubject, String msgContent,List<File> annexs) { MultiPartEmail multMail = new MultiPartEmail(); // SMTP multMail.setHostName(mailHost); multMail.setSmtpPort(smtpPort); // 需要提供公用的邮件用户名和密码 multMail.setAuthentication( mailUser, mailPassword); try { //multMail.setFrom(CodeRepositoryUtil.getValue("SysMail", "admin_email")); multMail.setFrom(mailFrom); multMail.addTo(mailTo); multMail.setSubject(msgSubject); multMail.setMsg(msgContent); for(File attachment: annexs){ multMail.attach(attachment); } multMail.send(); return true; } catch (EmailException e) { logger.error(e.getMessage(),e);//e.printStackTrace(); } return false; }
email.setSubject("Hi"); email.setMsg("This is a test mail ... :-)\n\nPlease check attachements that I have sent.\n\nThanks,\nFahim"); email.addTo(senderId); email.setTLS(true);
mm.addTo(x.getAddress()); } catch (EmailException e) { throw new ProcessException("Failed to add TO recipient.", e);
public static void main(String[] args) throws EmailException { // 创建附件 EmailAttachment attachment = new EmailAttachment(); attachment.setPath("mypictures/john.jpg"); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Picture of John"); attachment.setName("John"); // 创建 Email Message MultiPartEmail email = new MultiPartEmail(); email.setHostName("mail.myserver.com"); email.addTo("jdoe@somewhere.org", "John Doe"); email.setFrom("me@apache.org", "Me"); email.setSubject("The picture"); email.setMsg("Here is the picture you wanted"); // 追加附件 email.attach(attachment); // 发送 email.send(); } }
email.addTo(receiverId);
/** * Fill email. * * @param email * the email * @throws EmailException * the email exception * @throws IOException * Signals that an I/O exception has occurred. */ public void fillEmail(final MultiPartEmail email) throws EmailException, IOException { email.setHostName(getHost()); email.setSmtpPort(getSmtpPort()); email.addTo(getTo()); email.setFrom(getFrom()); email.setSubject(getSubject()); email.setMsg(getMsg()); email.setSSLOnConnect(isSecured()); if (isRequiresAuthentication()) { email.setAuthentication(getUsername(), getPassword()); } for (int i = 0; i < this.attachements.size(); i++) { final Attachment attachment = this.attachements.get(i); final ByteArrayDataSource ds = new ByteArrayDataSource(attachment.getData(), attachment.getMimeType()); email.attach(ds, attachment.getName(), attachment.getDescription()); } }