Guest User

Untitled

a guest
Jan 13th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Get email attachment and save into oracle table in google app script
  2. function testMail() {
  3. var threads = GmailApp.getInboxThreads();
  4. for (var i = 0; i < 10; i++) {
  5. var mess=threads[i].getMessages()[0];
  6. if (mess.getAttachments().length>0)
  7. {
  8. //var filename=mess.getAttachments()[0].
  9. Logger.log(mess.getSubject());
  10. Logger.log(mess.getAttachments()[0].getName());
  11. var conn = Jdbc.getConnection("jdbc:oracle:thin:@xxx.xxx.xxx.xxx/xxx.xxx.xxx", "xxx","xxxxxxx");
  12. conn.setAutoCommit(false);
  13. var stmt = conn.prepareStatement("insert into blob_table (filnname,blob_field) values (?,?)");
  14. stmt.setString(1, mess.getAttachments()[0].getName());
  15.  
  16. stmt.setBlob(2, mess.getAttachments()[0]);
  17. var res = stmt.execute();
  18. conn.commit();
  19. conn.close();
  20.  
  21. break;
  22. }
  23. }
  24. }
  25.  
  26. conn.createBlob().setBytes(0, myOriginalBlob)
Add Comment
Please, Sign In to add comment