/** * Este método é responsável por enviar email. * * @param pServidorSMTP * @param pDe * @param pPara * @param pCopia * @param pBcc * @param pAssunto * @param pTexto * @return true se o email for enviado, false caso contrário. */ public static boolean enviarEmail( final String pServidorSMTP, final String pDe, final String pPara, final String pCopia, final String pBcc, final String pAssunto, final String pTexto) { Properties mailPprops = new Properties(); mailPprops.put("mail.smtp.host", pServidorSMTP); Session mailSession = Session.getDefaultInstance(mailPprops, null); try { // Mudança: Aplicação usa ";", componente usa "," String para = pPara.replaceAll(";", ","); // Criando a mensagem MimeMessage msg = new MimeMessage(mailSession); // Atribuir rementente msg.setFrom(new InternetAddress(pDe)); // Atribuir destinatários InternetAddress[] endereco = null; // Para if ((para != null) && (!para.equals(""))) { endereco = InternetAddress.parse(para); msg.setRecipients(Message.RecipientType.TO, endereco); } // Cc if ((pCopia != null) && (!pCopia.equals(""))) { endereco = InternetAddress.parse(pCopia); msg.setRecipients(Message.RecipientType.CC, endereco); } // Bcc if ((pBcc != null) && (!pBcc.equals(""))) { endereco = InternetAddress.parse(pBcc); msg.setRecipients(Message.RecipientType.BCC, endereco); } // Atribuir assunto msg.setSubject(pAssunto); // Atribuir corpo do email (texto) if (pTexto != null) msg.setContent(pTexto, "text/html"); msg.setSentDate(new Date()); Transport.send(msg); msg = null; mailSession = null; } catch (MessagingException mex) { if (Constants.DEBUG) { mex.printStackTrace(System.out); } return false; } return true; }
public void sendEmail() throws MessagingException { if (msg.getFrom() == null) msg.setFrom(new InternetAddress("*****@*****.**")); msg.setHeader("X-mailer", "msgsend"); msg.setRecipients(Message.RecipientType.TO, (Address[]) toList.toArray(new Address[0])); msg.setRecipients(Message.RecipientType.CC, (Address[]) ccList.toArray(new Address[0])); msg.setRecipients(Message.RecipientType.BCC, (Address[]) bccList.toArray(new Address[0])); msg.setSentDate(new Date()); if (!toList.isEmpty()) Transport.send(msg); }
private MimeMessage getMessage(Email email, Session session) throws AddressException, MessagingException { MimeMessage result = new MimeMessage(session); result.setFrom(new InternetAddress(email.getFrom())); result.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email.getTo())); result.setSubject(email.getSubject()); if (email.getAttachment() != null) { // message body part MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(email.getMsg()); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); MimeBodyPart attachmentPart = new MimeBodyPart(); DataSource attachmentSource = new ByteArrayDataSource( email.getAttachment().getContent(), email.getAttachment().getAttachmentType()); attachmentPart.setDataHandler(new DataHandler(attachmentSource)); attachmentPart.setFileName(email.getAttachment().getFileName()); multipart.addBodyPart(attachmentPart); result.setContent(multipart); } else { result.setContent(email.getMsg(), "text/plain"); } return result; }
@Test public void shouldReceiveMessageAndSendOutgoingMail() throws Exception { // send test message to camel@localhost MimeMessage msg = new MimeMessage(session); msg.setSubject(SUBJECT); msg.setRecipients(RecipientType.TO, "camel@localhost"); msg.setText(PAYLOAD); Transport.send(msg); Thread.sleep(500); Message[] messages = inbox.getMessages(); // verify mailbox states, note that mock javamail do not create new // folders, so everything goes to same place assertEquals(2, messages.length); messages = read.getMessages(); assertEquals(2, messages.length); assertEquals(PAYLOAD, messages[0].getContent()); assertEquals(SUBJECT, messages[0].getSubject()); messages = riderInbox.getMessages(); assertEquals(1, messages.length); assertEquals("Forwarded message", messages[0].getSubject()); assertEquals(PAYLOAD, messages[0].getContent()); }
public boolean send() throws Exception { Properties props = _setProperties(); if (!_user.equals("") && !_pass.equals("") && _to.length > 0 && !_from.equals("") && !_subject.equals("") && !_body.equals("")) { Session session = Session.getInstance(props, this); MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(_from)); InternetAddress[] addressTo = new InternetAddress[_to.length]; for (int i = 0; i < _to.length; i++) { addressTo[i] = new InternetAddress(_to[i]); } msg.setRecipients(MimeMessage.RecipientType.TO, addressTo); msg.setSubject(_subject); msg.setSentDate(new Date()); // setup message body BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(_body); _multipart.addBodyPart(messageBodyPart); // Put parts in message msg.setContent(_multipart); // send email Transport.send(msg); return true; } else { return false; } }
public static MimeMessage createTextMessageWithAttachments( Session session, String subject, String text, Address from, Address[] to, Attachment... attachments) { MimeMessage msg = createEmptyMimeMessage(session); try { msg.setSubject(subject, charset); msg.setFrom(from); msg.setRecipients(Message.RecipientType.TO, to); Multipart multipart = new MimeMultipart(); MimeBodyPart textBodyPart = new MimeBodyPart(); textBodyPart.setText(text, charset); multipart.addBodyPart(textBodyPart); if (attachments != null) { for (Attachment attachment : attachments) { appendAttachment(multipart, attachment); } } msg.setContent(multipart); } catch (MessagingException ex) { throw new RuntimeException(ex); } return msg; }
public void send() { // Your SMTP server address here. String smtpHost = "myserver.jeffcorp.com"; // The sender's email address String from = "*****@*****.**"; // The recepients email address String to = "*****@*****.**"; Properties props = new Properties(); // The protocol to use is SMTP props.put("mail.smtp.host", smtpHost); Session session = Session.getDefaultInstance(props, null); try { InternetAddress[] address = {new InternetAddress(to)}; MimeMessage message; message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.setRecipients(Message.RecipientType.TO, to); message.setSubject("Hello from Jeff"); message.setSentDate(sendDate); message.setText("Hello Jeff, \nHow are things going?"); Transport.send(message); System.out.println("email has been sent."); } catch (Exception e) { System.out.println(e); } }
public static void sendEmail(String toEmail, String subject, String body) { try { Properties props = System.getProperties(); props.put("mail.smtp.host", "mail.excellenceserver.com"); // SMTP Host // props.put("mail.smtp.host", "smtp.gmail.com"); //SMTP Host props.put("mail.smtp.port", "27"); // TLS Port props.put("mail.smtp.auth", "true"); // enable authentication props.put("mail.smtp.starttls.enable", "true"); // enable STARTTLS Authenticator auth = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("*****@*****.**", "user@#123"); } }; Session session = Session.getInstance(props, auth); MimeMessage msg = new MimeMessage(session); // set message headers msg.addHeader("Content-type", "text/HTML; charset=UTF-8"); msg.addHeader("format", "flowed"); msg.addHeader("Content-Transfer-Encoding", "8bit"); msg.setFrom(new InternetAddress("*****@*****.**", "user@#123")); msg.setReplyTo(InternetAddress.parse("*****@*****.**", false)); msg.setSubject(subject, "UTF-8"); msg.setText(body, "UTF-8"); msg.setSentDate(new Date()); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail, false)); Transport.send(msg); } catch (Exception e) { e.printStackTrace(); } }
/** * Generate a MimeMessage with the specified attributes * * @param destEmailAddr The destination email address * @param fromEmailAddr The sender email address * @param fromName The senders display name * @param emailSubject The subject * @param emailPlainText The message body (plaintext) * @return The MimeMessage object * @throws Exception */ public static MimeMessage generateMail( String destEmailAddr, String destPersonalName, String fromEmailAddr, String fromName, String emailSubject, String emailPlainText) throws Exception { MimeMessage message = new MimeMessage(Session.getDefaultInstance(System.getProperties(), null)); InternetAddress[] toAddrs = InternetAddress.parse(destEmailAddr, false); if (destPersonalName != null) { toAddrs[0].setPersonal(destPersonalName); } InternetAddress from = new InternetAddress(fromEmailAddr); from.setPersonal(fromName); message.setRecipients(Message.RecipientType.TO, toAddrs); message.setFrom(from); message.setSubject(emailSubject); message.setSentDate(new java.util.Date()); MimeMultipart msgbody = new MimeMultipart(); MimeBodyPart html = new MimeBodyPart(); html.setDataHandler(new DataHandler(new MailDataSource(emailPlainText, "text/plain"))); msgbody.addBodyPart(html); message.setContent(msgbody); return message; }
public synchronized void sendImage( String subject, String body, String sender, String recipients, File attachment) throws Exception { try { MimeMessage message = new MimeMessage(session); message.setSender(new InternetAddress(sender)); message.setSubject(subject); MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(body); MimeBodyPart mbp2 = new MimeBodyPart(); FileDataSource fds = new FileDataSource(attachment); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); message.setContent(mp); if (recipients.indexOf(',') > 0) message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients)); else message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients)); Transport.send(message); } catch (Exception e) { Log.e("GmalSender", "Exception", e); } }
public void sendOTPToEmail(String to, String subject, String Username, String Password) { Properties props = new Properties(); props.put("mail.smtp.host", host); props.put("mail.smtp.port", port); switch (protocol) { case SMTPS: props.put("mail.smtp.ssl.enable", true); break; case TLS: props.put("mail.smtp.starttls.enable", true); break; } Authenticator authenticator = null; if (auth) { props.put("mail.smtp.auth", true); authenticator = new Authenticator() { private PasswordAuthentication pa = new PasswordAuthentication(username, password); @Override public PasswordAuthentication getPasswordAuthentication() { return pa; } }; } Session session = Session.getInstance(props, authenticator); MimeMessage message = new MimeMessage(session); try { message.setFrom(new InternetAddress(from)); InternetAddress[] address = {new InternetAddress(to)}; message.setRecipients(Message.RecipientType.TO, address); message.setSubject(subject); message.setSentDate(new Date()); /* message.setText(body); */ Multipart multipart = new MimeMultipart("alternative"); MimeBodyPart textPart = new MimeBodyPart(); // If email client does not support html------------------------- String textContent = "Username: "******" Password:"******"<html><h1>QCollect " + "</h1><p><h3>Please Use the following OTP to login to your Account</h3></p>" + Password + "</p></html>"; htmlPart.setContent(htmlContent, "text/html"); multipart.addBodyPart(textPart); multipart.addBodyPart(htmlPart); message.setContent(multipart); Transport.send(message); } catch (MessagingException ex) { ex.printStackTrace(); } }
/** * 设置抄送人 * * @param copyto String */ public boolean setCopyTo(String copyto) { if (copyto == null) return false; try { mimeMsg.setRecipients(Message.RecipientType.CC, (Address[]) InternetAddress.parse(copyto)); return true; } catch (Exception e) { return false; } }
/** * 设置收信人 * * @param to String */ public boolean setTo(String to) { if (to == null) return false; try { mimeMsg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); return true; } catch (Exception e) { return false; } }
/** * Send an email over SMTP. * * @param _to recipient * @param _cc cc'd users * @param _bcc bcc'd users * @param _subject the subject * @param _file path to attachment * @param _message the message * @throws MessagingException the messaging exception */ public void send( String _to, String _cc, String _bcc, String _subject, String _file, String _message) throws MessagingException { MimeMessage message = new MimeMessage(SESSION); message.setFrom(new InternetAddress(CONFIG.getProperty("mail.address"))); message.setRecipients(Message.RecipientType.TO, _to); if (_cc.length() > 0) message.setRecipients(Message.RecipientType.CC, _cc); if (_bcc.length() > 0) message.setRecipients(Message.RecipientType.BCC, _bcc); message.setSubject(_subject); message.setText(_message); message.saveChanges(); send(message); }
public MimeMessageBuilder setRecipients( final Message.RecipientType recipientType, final String recipients) throws MessagingException { final InternetAddress[] addresses = parseAddresses(recipients); if (null != addresses) { message.setRecipients(recipientType, addresses); } return this; }
private void sendEmail(String subject, String body, String to) throws MessagingException { log.debug("Sending e-mail message to '" + to + "' with subject: " + subject); MimeMessage msg = new MimeMessage(session); msg.setFrom(); msg.setRecipients(Message.RecipientType.TO, to); msg.setSubject(subject); msg.setSentDate(new Date()); msg.setText(body); Transport.send(msg); }
public static MimeMessage createMessage( Session session, String subject, String html, String text, Address from, Address[] to, Attachment... attachments) { if (text == null) text = Html.convertHtmlToText(html); MimeMessage msg = createEmptyMimeMessage(session); try { msg.setSubject(subject, charset); msg.setFrom(from); msg.setRecipients(Message.RecipientType.TO, to); if ((attachments == null || attachments.length == 0)) { // no attachments if (Str.isBlank(html)) { // no html msg.setText(text, charset); return msg; } msg.setContent(createMultipartAlternative(text, html)); return msg; } MimeMultipart multipartMixed = new MimeMultipart("mixed"); if (Str.isBlank(html)) { // no html MimeBodyPart textBodyPart = new MimeBodyPart(); textBodyPart.setText(text, charset); multipartMixed.addBodyPart(textBodyPart); } else { // html MimeBodyPart wrapAlternative = new MimeBodyPart(); wrapAlternative.setContent(createMultipartAlternative(text, html)); multipartMixed.addBodyPart(wrapAlternative); } for (Attachment attachment : attachments) { appendAttachment(multipartMixed, attachment); } msg.setContent(multipartMixed); return msg; } catch (MessagingException ex) { throw new RuntimeException(ex); } }
protected void sendFile() throws Exception { System.out.println("send file yaar"); Properties props = new Properties(); Session session = Session.getInstance(props, null); message123 = new MimeMessage(session); try { message123.setFrom(new InternetAddress(username.getText())); } catch (AddressException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } message123.setRecipients(Message.RecipientType.TO, emailID.getText()); message123.setSubject("JavaMail Attachment"); BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText("Here's the file"); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(str); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(str); multipart.addBodyPart(messageBodyPart); message123.setContent(multipart); /* try { Transport tr = session.getTransport("smtps"); tr.connect(SMTP_HOST_NAME, username.getText(), password.getText()); tr.sendMessage(message123, message123.getAllRecipients()); System.out.println("Mail Sent Successfully"); tr.close(); } catch (SendFailedException sfe) { System.out.println(sfe); }*/ }
private void sendReplyFromPostmaster(Mail mail, String stringContent) { try { MailAddress notifier = getMailetContext().getPostmaster(); MailAddress senderMailAddress = mail.getSender(); MimeMessage message = mail.getMessage(); // Create the reply message MimeMessage reply = new MimeMessage(Session.getDefaultInstance(System.getProperties(), null)); // Create the list of recipients in the Address[] format InternetAddress[] rcptAddr = new InternetAddress[1]; rcptAddr[0] = senderMailAddress.toInternetAddress(); reply.setRecipients(Message.RecipientType.TO, rcptAddr); // Set the sender... reply.setFrom(notifier.toInternetAddress()); // Create the message body MimeMultipart multipart = new MimeMultipart(); // Add message as the first mime body part MimeBodyPart part = new MimeBodyPart(); part.setContent(stringContent, "text/plain"); part.setHeader(RFC2822Headers.CONTENT_TYPE, "text/plain"); multipart.addBodyPart(part); reply.setContent(multipart); reply.setHeader(RFC2822Headers.CONTENT_TYPE, multipart.getContentType()); // Create the list of recipients in our MailAddress format Set<MailAddress> recipients = new HashSet<MailAddress>(); recipients.add(senderMailAddress); // Set additional headers if (reply.getHeader(RFC2822Headers.DATE) == null) { reply.setHeader(RFC2822Headers.DATE, rfc822DateFormat.format(new java.util.Date())); } String subject = message.getSubject(); if (subject == null) { subject = ""; } if (subject.indexOf("Re:") == 0) { reply.setSubject(subject); } else { reply.setSubject("Re:" + subject); } reply.setHeader(RFC2822Headers.IN_REPLY_TO, message.getMessageID()); // Send it off... getMailetContext().sendMail(notifier, recipients, reply); } catch (Exception e) { log("Exception found sending reply", e); } }
public void envia() throws AddressException, MessagingException { Session session = Session.getInstance(this.propriedades, this.authentication); MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress("*****@*****.**")); message.setRecipients(Message.RecipientType.TO, "*****@*****.**"); message.setSentDate(new Date()); message.setSubject("Teste envio jsf"); message.setContent("Sua solicitação foi aprovada: OS nº" + this.os, "text/plain"); Transport.send(message); }
public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception { MimeMessage message = new MimeMessage(session); DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain")); message.setSender(new InternetAddress(sender)); message.setSubject(subject); message.setDataHandler(handler); if (recipients.indexOf(',') > 0) message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients)); else message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients)); Transport.send(message); }
public static MimeMessage createTextMessage( Session session, String subject, String text, Address from, Address[] to) { MimeMessage msg = createEmptyMimeMessage(session); try { msg.setSubject(subject, charset); msg.setText(text, charset); msg.setFrom(from); msg.setRecipients(Message.RecipientType.TO, to); } catch (MessagingException ex) { throw new RuntimeException(ex); } return msg; }
private static MimeMessage createMsg( String to, String from, String cc, String bcc, String message, String subject, Session session) throws Exception { if (logger.isTraceEnabled()) logger.trace( String.format( "createMsg(to=%s, from=%s, cc=%s, bcc=%s, message=%s, subject=%s)", String.valueOf(to), String.valueOf(from), String.valueOf(cc), String.valueOf(bcc), String.valueOf(message), String.valueOf(subject))); MimeMessage msg = new MimeMessage(session); msg.setFrom(tranFromAddr(from)); if (to != null && !"".equals(to.trim())) { msg.setRecipients(Message.RecipientType.TO, UtilsTools.tranAddr(to.trim())); } if (cc != null && !"".equals(cc.trim())) { msg.setRecipients(Message.RecipientType.CC, UtilsTools.tranAddr(cc.trim())); } if (bcc != null && !"".equals(bcc.trim())) { msg.setRecipients(Message.RecipientType.BCC, UtilsTools.tranAddr(bcc.trim())); } msg.setSubject(subject); msg.setText(message); msg.saveChanges(); return msg; }
public static void sendMail(String[] addresses, String subject, String message) throws UnsupportedEncodingException, MessagingException { MimeMessage mimeMessage = new MimeMessage(Mailer.descriptor().createSession()); String adminAddress = JenkinsLocationConfiguration.get().getAdminAddress(); InternetAddress[] to = new InternetAddress[addresses.length]; for (int i = 0; i < addresses.length; i++) { to[i] = new InternetAddress(addresses[i], true); } mimeMessage.setSender(new InternetAddress(adminAddress)); mimeMessage.setRecipients(Message.RecipientType.TO, to); mimeMessage.setSubject(subject, "ISO-2022-JP"); mimeMessage.setText(message, "ISO-2022-JP"); Transport.send(mimeMessage); }
public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception { try { message = new MimeMessage(session); DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain")); message.setSender(new InternetAddress(sender)); message.setSubject(subject); message.setDataHandler(handler); if (recipients.indexOf(',') > 0) message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients)); else message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients)); Thread Subthread = new Thread(mutiThread); // 開一個新的線程,去執行網路連線 Subthread.start(); } catch (Exception e) { Log.v("ErrorMail", e.toString()); } }
/** * Funkcija za slanje poruke koja se poziva pritiskom na gumb unutar prikaza slanja poruka. * * @return */ public String saljiPoruku() { EmailPovezivanje ep = (EmailPovezivanje) FacesContext.getCurrentInstance() .getExternalContext() .getSessionMap() .get("emailPovezivanje"); this.emailPosluzitelj = ep.getEmailPosluzitelj(); try { // Create the JavaMail session java.util.Properties properties = System.getProperties(); properties.put("mail.smtp.host", this.emailPosluzitelj); Session session = Session.getInstance(properties, null); // Construct the message MimeMessage message = new MimeMessage(session); // Set the from address Address fromAddress = new InternetAddress(this.saljePoruku); message.setFrom(fromAddress); // Parse and set the recipient addresses Address[] toAddresses = InternetAddress.parse(this.primaPoruku); message.setRecipients(Message.RecipientType.TO, toAddresses); // Set the subject and text message.setSubject(this.predmetPoruke); message.setText(this.sadrzajPoruke); message.setSentDate(new Date()); Transport.send(message); this.uspjesnoPoslano = true; this.primaPoruku = null; this.predmetPoruke = null; this.sadrzajPoruke = null; System.out.println("Slanje poruke uspješno"); } catch (AddressException e) { e.printStackTrace(); } catch (SendFailedException e) { e.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } return null; }
public Message getMessage() throws MessagingException { final String from = "*****@*****.**"; final String to = "*****@*****.**"; // you may need to substitute some values here final Properties p = new Properties(); p.setProperty("mail.host", "localhost"); p.setProperty("mail.transport.protocol", "smtp"); p.setProperty("mail.smtp.connectiontimeout", "10000"); p.setProperty("mail.smtp.timeout", "10000"); final Session s = Session.getInstance(p); final MimeMessage m = new MimeMessage(s); m.setFrom(new InternetAddress(from)); m.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); return m; }
public static void sendMail( String smtpServer, String from, String to, String subject, String body) { try { MimeMessage msg = new MimeMessage(getMailSession(smtpServer)); msg.setFrom(new InternetAddress(from)); msg.setRecipients(Message.RecipientType.TO, to); if (subject == null || subject.equals("")) { subject = TEXT_NO_SUBJECT; } msg.setSubject(subject); msg.setText(body, "UTF-8"); msg.setSentDate(new Date()); // Transport.send(msg); } catch (Throwable e) { throw new DeepaMehtaException(e.toString(), e); } }
public void send(String title, String[] receiver, String content) { Properties properties = new Properties(); try { properties.load(getClass().getResourceAsStream("/config/emailauth.properties")); Authenticator authenticator = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( properties.getProperty("mail.smtp.user"), properties.getProperty("mail.smtp.password")); } }; Session session = Session.getInstance(properties, authenticator); session.setDebug(false); MimeMessage message = new MimeMessage(session); message.addHeader("Content-type", "text/HTML; charset=UTF-8"); message.addHeader("format", "flowed"); message.addHeader("Content-Transfer-Encoding", "8bit"); message.setFrom(new InternetAddress(properties.getProperty("mail.smtp.user"), "관리자")); message.setReplyTo(InternetAddress.parse(properties.getProperty("mail.smtp.user"), false)); message.setSubject(title, "UTF-8"); message.setText(content, "UTF-8"); message.setSentDate(new Date()); for (int i = 0; i < receiver.length; i++) { message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(receiver[i], false)); } Transport.send(message); } catch (IOException ie) { // TODO Auto-generated catch block ie.printStackTrace(); } catch (MessagingException me) { me.printStackTrace(); } }
public void sendMessage(NMessage m) throws Exception { ensureConnected(); // Create a new message with values from dialog. MimeMessage newMessage = new MimeMessage(session); newMessage.setFrom(new InternetAddress(from /* m.getFrom() */)); newMessage.setSubject(m.getName()); newMessage.setSentDate(m.getWhen()); newMessage.setContent(m.getContent(), "text/html"); final Address[] recipientAddresses = InternetAddress.parse(m.getTo()); newMessage.setRecipients(Message.RecipientType.TO, recipientAddresses); Transport transport = session.getTransport("smtps"); transport.connect(getSmtpServer(), GMAIL_SMTP_PORT, getUsername(), getPassword()); transport.sendMessage(newMessage, recipientAddresses); transport.close(); }