List of usage examples for javax.mail.internet MimeMessage setText
@Override public void setText(String text) throws MessagingException
From source file:jp.mamesoft.mailsocketchat.Mail.java
public static void Send(String to, int mode) { //mode 0 = ?, 1 = ?, 2 = ?, 3 = ??, 4 = , 5 = System.out.println("???"); String from = Mailsocketchat.mail_user; String host = "smtp.gmail.com"; String port = "465"; String text = ""; String subject = ""; if (mode == 0) { text = logprint(text);//from w w w.ja va 2s .c o m subject = " - MailSocketChat"; if (Mailsocketchat.newver) { text = text + "\n\n??????????\n"; } } if (mode == 1) { if (Mailsocketchat.subjectname) { subject = Mailsocketchat.logs.get(0).get("name"); } else { subject = "?? - MailSocketChat"; } text = logprint(text); } if (mode == 8) { text = logprint(text); subject = "?? - MailSocketChat"; } if (mode == 2) { if (!Mailsocketchat.push) { subject = "????? - MailSocketChat"; text = "???????????????????\n\n??????\n"; text = logprint(text); } else { subject = "??? - MailSocketChat"; text = "?????????????????\n(???????????)\n\n"; } if (Mailsocketchat.newver) { text = text + "\n\n??????????\n"; } } if (mode == 3) { if (!Mailsocketchat.push && !Mailsocketchat.repeat) { subject = "???? - MailSocketChat"; text = "????\n\n??????\n"; text = logprint(text); } else { subject = "?????? - MailSocketChat"; text = "?????????????????\n\n"; if (Mailsocketchat.repeat) { text = text + "??????\n"; text = logprint(text); } } if (Mailsocketchat.newver) { text = text + "\n\n??????????\n"; } } if (mode == 7) { if (!Mailsocketchat.repeat) { subject = "????? - MailSocketChat"; text = "?????30????????????\n\n"; if (!Mailsocketchat.push) { text = text + "??????\n"; text = logprint(text); } } else { subject = "??? - MailSocketChat"; text = "???\n\n"; } if (Mailsocketchat.newver) { text = text + "\n\n??????????\n"; } } if (mode == 4) { subject = " - MailSocketChat"; int userint = Mailsocketchat.users.size(); int romint = Mailsocketchat.roms.size(); text = ": " + userint + " ROM: " + romint + "\n\n\n"; for (Integer id : Mailsocketchat.users.keySet()) { HashMap<String, String> data = Mailsocketchat.users.get(id); text = text + data.get("name") + "\n"; text = text + " (" + data.get("ip") + ")\n"; } text = text + "\n\nROM\n"; for (Integer id : Mailsocketchat.roms.keySet()) { HashMap<String, String> data = Mailsocketchat.roms.get(id); text = text + data.get("ip") + "\n"; } if (Mailsocketchat.newver) { text = text + "\n\n??????????\n"; } } if (mode == 5) { subject = " - MailSocketChat"; if (Mailsocketchat.push) { text = "??: \n\n"; } else if (Mailsocketchat.repeat) { text = "??: \n\n"; } else { text = "??: ?\n\n"; } text = text + "?\n"; text = text + "?(fetch): ?????\n"; text = text + "(push): ????\n"; text = text + "(repeat): ????\n"; text = text + "(list): ???\n"; text = text + "#: ?????\n"; text = text + "#hoge: ??hoge????\n"; text = text + "(help): ?????\n\n"; text = text + "\nMailSocketChat Ver." + Mailsocketchat.version + "\n"; if (Mailsocketchat.newver) { text = text + "??????????\n"; } } if (mode == 6) { subject = "????????? - MailSocketChat"; text = text + "MailSocketChat??????????????????\n"; } // create some properties and get the default Session Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.transport.protocol", "smtps"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.socketFactory.fallback", "false"); props.put("mail.smtp.host", host); props.put("mail.smtp.port", port); Session sendsession = Session.getInstance(props, new PlainAuthenticator(Mailsocketchat.mail_user, Mailsocketchat.mail_pass)); try { // create a message MimeMessage msg = new MimeMessage(sendsession); msg.setFrom(new InternetAddress(from)); InternetAddress[] sendaddress = { new InternetAddress(to) }; msg.setRecipients(Message.RecipientType.TO, sendaddress); msg.setSubject(subject); msg.setSentDate(new Date()); // If the desired charset is known, you can use // setText(text, charset) msg.setText(text); Transport.send(msg); System.out.println("?????"); } catch (MessagingException mex) { System.out.println("??????"); } }
From source file:de.hybris.platform.cuppytrail.forgotpassword.actions.SendEmailAction.java
@Override public void executeAction(final ForgotPasswordProcessModel process) throws RetryLaterException, Exception { final EmailMessageModel emailMessage = process.getEmailMessage(); final MimeMessagePreparator preparator = new MimeMessagePreparator() { @Override//from www. j a v a 2 s. co m public void prepare(final MimeMessage message) throws Exception { message.setSubject(emailMessage.getSubject()); message.setText(emailMessage.getBody()); message.setRecipients(RecipientType.TO, emailMessage.getRecipientAddress()); } }; mailSender.send(preparator); }
From source file:gwtupload.sendmailsample.server.SendMailSampleServlet.java
@Override public String executeAction(HttpServletRequest request, List<FileItem> sessionFiles) throws UploadActionException { try {/*from w w w. j av a2 s .c o m*/ String from = null, to = null, subject = "", body = ""; // create a new multipart content MimeMultipart multiPart = new MimeMultipart(); for (FileItem item : sessionFiles) { if (item.isFormField()) { if ("from".equals(item.getFieldName())) from = item.getString(); if ("to".equals(item.getFieldName())) to = item.getString(); if ("subject".equals(item.getFieldName())) subject = item.getString(); if ("body".equals(item.getFieldName())) body = item.getString(); } else { // add the file part to multipart content MimeBodyPart part = new MimeBodyPart(); part.setFileName(item.getName()); part.setDataHandler( new DataHandler(new ByteArrayDataSource(item.get(), item.getContentType()))); multiPart.addBodyPart(part); } } // add the text part to multipart content MimeBodyPart txtPart = new MimeBodyPart(); txtPart.setContent(body, "text/plain"); multiPart.addBodyPart(txtPart); // configure smtp server Properties props = System.getProperties(); props.put("mail.smtp.host", SMTP_SERVER); // create a new mail session and the mime message MimeMessage mime = new MimeMessage(Session.getInstance(props)); mime.setText(body); mime.setContent(multiPart); mime.setSubject(subject); mime.setFrom(new InternetAddress(from)); for (String rcpt : to.split("[\\s;,]+")) mime.addRecipient(Message.RecipientType.TO, new InternetAddress(rcpt)); // send the message Transport.send(mime); } catch (MessagingException e) { throw new UploadActionException(e.getMessage()); } return "Your mail has been sent successfuly."; }
From source file:net.sourceforge.subsonic.backend.service.EmailSession.java
public void sendMessage(String from, List<String> to, List<String> cc, List<String> bcc, List<String> replyTo, String subject, String text) throws MessagingException { MimeMessage message = createMessage(from, to, cc, bcc, replyTo, subject); message.setText(text); sendMessage(message);/*from w w w. j a va 2s .c o m*/ }
From source file:com.eatcodesleep.web.MailRestController.java
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public String sendMail(@RequestBody final TextEmail textEmail) { javaMailSender.send((MimeMessage mimeMessage) -> { mimeMessage.setFrom(textEmail.getFromAddress()); mimeMessage.setRecipients(Message.RecipientType.TO, textEmail.getToAddressesAsCommaSeparatedString()); mimeMessage.setText(textEmail.getMessage()); });/*from w ww . j a v a 2 s . com*/ return "Success!!!"; }
From source file:br.com.valecard.listeners.SendMailListener.java
@Override public void onApplicationEvent(SendMailEvent event) { MimeMessage mm = mailSender.createMimeMessage(); final String property = event.getProperty(); try {//from w w w . j a va 2 s .c o m mm.setRecipients(Message.RecipientType.TO, property); mm.setText(property); // mm.addHeader(XMC_TRACK, track); // mm.addHeader(XMC_TEMPLATE, property); // mm.addHeader(XMC_MERGE_VARS, mergeVars); } catch (MessagingException ex) { LOG.log(Level.WARNING, ex.getMessage(), ex); } try { mailSender.send(mm); } catch (MailException ex) { LOG.log(Level.WARNING, ex.getMessage(), ex); } }
From source file:com.bitranger.parknshop.mail.EMailSender.java
public boolean send(String address, String subject, String content) { LOG.debug("sending message [" + subject + "] to [" + address + "]"); MimeMessage msg = sender.createMimeMessage(); try {/*from www.j a v a 2 s. c o m*/ msg.setRecipient(RecipientType.TO, new InternetAddress(address)); msg.setSubject(subject); msg.setText(content); sender.send(msg); } catch (Exception e) { LOG.error("failed sending email to [" + address + "]" + " subject [" + subject + "] content[" + content + "]"); return false; } return false; }
From source file:org.tsm.concharto.service.EmailService.java
/** * * @param subject//from w ww. j a v a 2 s .c o m * @param body * @param sender * @param recipients */ public void SendIndividualMessages(String subject, String body, InternetAddress sender, String[] recipients) { int emailErrorCount = 0; for (int i = 0; i < recipients.length; i++) { String recipientEmailAddress = recipients[i]; MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties())); try { message.setText(body); message.setSubject(subject); message.setFrom(sender); message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipientEmailAddress)); sendMessage(message); } catch (Exception e) { log.error(e.getMessage(), e); emailErrorCount++; } } if (emailErrorCount > 0) { String message = emailErrorCount + " out of " + recipients.length + " emails could not be sent."; log.error(message); } }
From source file:org.apache.archiva.redback.integration.mail.MailerImpl.java
public void sendMessage(Collection<String> recipients, String subject, String content) { if (recipients.isEmpty()) { log.warn("Mail Not Sent - No mail recipients for email. subject [{}]", subject); return;/*from w w w. j a va 2 s . c o m*/ } String fromAddress = config.getString(UserConfigurationKeys.EMAIL_FROM_ADDRESS); String fromName = config.getString(UserConfigurationKeys.EMAIL_FROM_NAME); if (StringUtils.isEmpty(fromAddress)) { fromAddress = System.getProperty("user.name") + "@localhost"; } // TODO: Allow for configurable message headers. try { MimeMessage message = javaMailSender.createMimeMessage(); message.setSubject(subject); message.setText(content); InternetAddress from = new InternetAddress(fromAddress, fromName); message.setFrom(from); List<Address> tos = new ArrayList<Address>(); for (String mailbox : recipients) { InternetAddress to = new InternetAddress(mailbox.trim()); tos.add(to); } message.setRecipients(Message.RecipientType.TO, tos.toArray(new Address[tos.size()])); log.debug("mail content {}", content); javaMailSender.send(message); } catch (AddressException e) { log.error("Unable to send message, subject [{}]", subject, e); } catch (MessagingException e) { log.error("Unable to send message, subject [{}]", subject, e); } catch (UnsupportedEncodingException e) { log.error("Unable to send message, subject [{}]", subject, e); } }
From source file:SendMailBean.java
public void emailPassword(String email, String memberName, String password) { String host = "mail"; String from = "w@j.com"; Properties props = System.getProperties(); props.put("mail.smtp.host", host); Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); try {// ww w.j a v a 2 s . c o m message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); message.setSubject("Password Reminder"); message.setText("Hi " + memberName + ",\nYour password is: " + password + "\nregards - " + from); Transport.send(message); } catch (AddressException ae) { } catch (MessagingException me) { } }