Beispiel #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);
 }
  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();
  }
Beispiel #3
0
 /**
  * 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);
 }
Beispiel #4
0
 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());
   }
 }
Beispiel #5
0
 public void setHTML(String htmlMsg) throws MessagingException {
   msg.setDataHandler(new DataHandler(new ByteArrayDataSource(htmlMsg, "text/html")));
 }