| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 
 | import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
 
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
 
public class SendMail {
                public static void main(String[] args) {  
 
                    ActiveXComponent oOutlook = new ActiveXComponent("Outlook.Application");  
                    Dispatch.call(oOutlook ,"GetNamespace","MAPI").toDispatch();
                    Dispatch email = Dispatch.invoke(oOutlook.getObject(),"CreateItem", Dispatch.Get, new Object[] { "0" }, new int[0]).toDispatch();  
                    Dispatch.put(email, "To", "xxx@xxx.com");  
                    Dispatch.put(email, "Subject", "xxx");  
                    Dispatch.put(email, "Body", "xxx");  
                    Dispatch.put(email, "Body", getCuerpoEmail("C:\\log.txt"));
                    Dispatch.put(email, "ReadReceiptRequested", "false"); 
                    try {  
                        Dispatch.call(email, "Send");  
                    } catch (com.jacob.com.ComFailException e) {  
                        e.printStackTrace();  
                    }  
           }
                public static String getCuerpoEmail(String fileName)
               {
                   String message = null;
                   FileInputStream file;
                   try {
                       file = new FileInputStream(fileName);
                       byte[] b = new byte[file.available()];
                       file.read(b);
                       file.close();
                       message = new String(b);
                   } catch (FileNotFoundException e) {
                       e.printStackTrace();
                   } catch (IOException e) {
                       e.printStackTrace();
                   }
                   return message;
               }
       } | 
Partager