Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>it's a complete code for send email with attachments. You can send multiple attachments a single message, just add all parts to Multipart.</p> <pre><code> try { // create a multipart StringBuffer sbFileBody = new StringBuffer(); Multipart mp = new Multipart(); TextBodyPart tbp = new TextBodyPart(mp, "your message body"); SupportedAttachmentPart sap = new SupportedAttachmentPart(mp, "text/plain", "info.txt", sbFileBody.toString().getBytes("UTF-8")); mp.addBodyPart(tbp); mp.addBodyPart(sap); ServiceConfiguration sc = null; ServiceRecord[] records = ServiceBook.getSB().getRecords(); for (int i = 0; i &lt; records.length; i++) { if (records[i].getCid().equalsIgnoreCase("CMIME") &amp;&amp; !records[i].isDisabled() &amp;&amp; records[i].isValid()) { ServiceConfiguration sct = new ServiceConfiguration(records[i]); String mailAddress = sct.getEmailAddress().toLowerCase(); if (mailAddress.equals("from@address.com")) { //use sc; sc = sct; break; } } } if (sc != null) { Session session = Session.getInstance(sc); Store store = session.getStore(); Folder[] folders = store.list(Folder.SENT); Folder sentfolder = folders[0]; if (sentfolder != null) { Message message = new Message(sentfolder); Address toAdress = new Address("to@address.com", "to address"); message.setFrom(new Address(sc.getEmailAddress(), sc.getName())); message.addRecipients(Message.RecipientType.TO, new Address[] { toAdress }); message.setSubject("Your mail subject"); message.setContent(mp); message.addMessageListener(new MessageListener() { public void changed(MessageEvent e) { if (e.getMessage().getStatus() == Message.Status.TX_SENT) { try { e.getMessage().removeMessageListener(this); System.out.println("Send complete"); } catch (Exception ex) { ex.printStackTrace(); } } } }); Transport.send(message); } } } catch (Exception e) { e.printStackTrace(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload