コード例 #1
0
 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);
 }
コード例 #2
0
  public synchronized void sendMail(Mail m) throws MessagingException {

    MimeMessage message = new MimeMessage(session);
    DataHandler handler =
        new DataHandler(new ByteArrayDataSource(m.getBody().getBytes(), "text/plain"));
    message.setSender(new InternetAddress(m.getSender()));
    message.setSubject(m.getSubject());
    message.setDataHandler(handler);
    message.setRecipient(Message.RecipientType.TO, new InternetAddress(m.getRecipient()));
    Transport tr = session.getTransport("smtp");
    tr.connect(user, password);
    tr.send(message);
    tr.close();
  }
コード例 #3
0
ファイル: Mail.java プロジェクト: gmfawcett/openmark-mvn
 /**
  * Sends the given mail message with a given MIME format.
  *
  * @param from Sender address
  * @param replyTo Reply-to address
  * @param to Array of target addresses
  * @param cc Array of CC addresses - or null
  * @param subject Subject
  * @param message Message
  * @param mimeType Mime-type of the message; if null, sends text/plain.
  * @throws MessagingException If any failure occurs in contacting mail server etc.
  */
 public static void send(
     String from,
     String replyTo,
     String[] to,
     String[] cc,
     String subject,
     String message,
     String mimeType)
     throws MessagingException {
   MimeMessage mm = createMessage(from, replyTo, to, cc, subject);
   if (mimeType == null) {
     mm.setText(message, "UTF-8");
   } else {
     mm.setDataHandler(new DataHandler(message, mimeType));
   }
   Transport.send(mm);
 }
コード例 #4
0
ファイル: GmailSender.java プロジェクト: HarrisQs/DropDrip
 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());
   }
 }
コード例 #5
0
ファイル: Email.java プロジェクト: vishu018/franklin
 public void setHTML(String htmlMsg) throws MessagingException {
   msg.setDataHandler(new DataHandler(new ByteArrayDataSource(htmlMsg, "text/html")));
 }