简体   繁体   中英

How to send an email with attachment in domino server using notes java api?

I have Java code to send email in domino server without attachment. I want to get it working with attachments also.

try {
       Session dominoSession = NotesFactory.createSession( host, username, password );
       System.out.println("USER Detail : "+dominoSession.getUserName());
       Database dominoDb = dominoSession.getDatabase( host, mailbox );

       Document memo = dominoDb.createDocument();
       memo.appendItemValue( "Form", "Memo" );
       memo.appendItemValue( "Importance", "1" );
       memo.appendItemValue( "CopyTo", copyTo );
       memo.appendItemValue( "Subject", subject );
       memo.appendItemValue( "Body", message );
       memo.send( false, sendTo );

       dominoDb.recycle();
       dominoSession.recycle();
      }
      catch ( NotesException e )
      {
       System.out.println( "Error - " + e.toString() );
      }
      catch ( Exception e )
      {
       System.out.println( "Error - " + e.toString() );
      }

First of all, you should not use appendItemValue(). You use replaceItemValue() to insert data into text fields.

Second, the field 'body' is a rich text dfield. You need to use the methods and properties of the NotesRichTextItem class to work with rich text. Then you also have the ability to attach files. It is all described in the help file, with examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM