生成附件的数据流不保存在本地硬盘而是直接放入附件发送,这如何实现?

解决方案 »

  1.   

    private class MailSource implements InputStreamSource {
    private String content; /**
     * 
     */
    public MailSource(String content) {
    this.content = content;
    } /*
     * (non-Javadoc)
     * 
     * @see org.springframework.core.io.InputStreamSource#getInputStream()
     */
    public InputStream getInputStream() throws IOException {
    // ByteArrayOutputStream bo = new ByteArrayOutputStream();
    // bo.write(content.getBytes());
    // bo.flush();
    // ByteArrayInputStream bi = new
    // ByteArrayInputStream(bo.toByteArray());
    // bo.close();
    // System.out.println("Return byte array inputstream");
    return new ByteArrayInputStream(content.getBytes());
    } }