Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.57 KB | None | 0 0
  1. public boolean send(String[] toAddress, String fromAddress, String subject,
  2. String body, String filename) throws Exception {
  3. Properties props = setProperties();
  4.  
  5. try{
  6. Session session = Session.getInstance(props, this);
  7. session.setDebug(true);
  8.  
  9. MimeMessage msg = new MimeMessage(session);
  10.  
  11. msg.setFrom(new InternetAddress(fromAddress));
  12.  
  13. InternetAddress[] addressTo = new InternetAddress[toAddress.length];
  14. for(int i=0; i<toAddress.length; i++){
  15. addressTo[i] = new InternetAddress(toAddress[i]);
  16. }
  17.  
  18. msg.setRecipients(MimeMessage.RecipientType.TO, addressTo);
  19. msg.setSubject(subject);
  20. msg.setSentDate(new Date());
  21.  
  22.  
  23. BodyPart messageBodyPart1 = new MimeBodyPart();
  24. messageBodyPart1.setText(body);
  25. multi.addBodyPart(messageBodyPart1);
  26.  
  27. BodyPart messageBodyPart2 = new MimeBodyPart();
  28. DataSource source = new FileDataSource(filename);
  29. messageBodyPart2.setDataHandler(new DataHandler(source));
  30. messageBodyPart2.setFileName("record.csv");
  31. multi.addBodyPart(messageBodyPart2);
  32.  
  33. BodyPart messageBodyPart3 = new MimeBodyPart();
  34. messageBodyPart3.setText("");
  35. multi.addBodyPart(messageBodyPart3);
  36.  
  37. msg.setContent(multi);
  38.  
  39. Transport transport = session.getTransport("smtp");
  40. transport.connect(host, 25, user, password);
  41. transport.sendMessage(msg, msg.getAllRecipients());
  42. transport.close();
  43. return true;
  44. } catch (Exception e) {
  45. e.printStackTrace();
  46. return false;
  47. }
  48. }
  49.  
  50. 08-16 15:09:33.337: I/System.out(6314): EHLO localhost
  51. 08-16 15:09:33.345: I/System.out(6314): 250-web.mysmtp.com Hello localhost [202.155.209.250]
  52. 08-16 15:09:33.345: I/System.out(6314): 250-SIZE 52428800
  53. 08-16 15:09:33.345: I/System.out(6314): 250-PIPELINING
  54. 08-16 15:09:33.345: I/System.out(6314): 250-AUTH PLAIN LOGIN
  55. 08-16 15:09:33.345: I/System.out(6314): 250-STARTTLS
  56. 08-16 15:09:33.345: I/System.out(6314): 250 HELP
  57. 08-16 15:09:33.345: I/System.out(6314): DEBUG SMTP: Found extension "SIZE", arg "52428800"
  58. 08-16 15:09:33.345: I/System.out(6314): DEBUG SMTP: Found extension "PIPELINING", arg ""
  59. 08-16 15:09:33.345: I/System.out(6314): DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
  60. 08-16 15:09:33.345: I/System.out(6314): DEBUG SMTP: Found extension "STARTTLS", arg ""
  61. 08-16 15:09:33.345: I/System.out(6314): DEBUG SMTP: Found extension "HELP", arg ""
  62. 08-16 15:09:33.353: I/System.out(6314): DEBUG SMTP: Attempt to authenticate
  63. 08-16 15:09:33.353: I/System.out(6314): AUTH LOGIN
  64. 08-16 15:09:33.361: I/System.out(6314): 334 VXNlcm5hbWU6
  65. 08-16 15:09:33.361: I/System.out(6314): Y2xpZW50YWxlcnRzQHVuaXNlcnZlaXQuY29t
  66. 08-16 15:09:33.368: I/System.out(6314): 334 UGFzc3dvcmQ6
  67. 08-16 15:09:33.368: I/System.out(6314): cEBzc3cwcmQhIUA=
  68. 08-16 15:09:33.384: I/System.out(6314): 235 Authentication succeeded
  69. 08-16 15:09:33.392: I/System.out(6314): DEBUG SMTP: use8bit false
  70. 08-16 15:09:33.392: I/System.out(6314): MAIL FROM:<me@mysmtp.com>
  71. 08-16 15:09:33.415: I/System.out(6314): 250 OK
  72. 08-16 15:09:33.415: I/System.out(6314): RCPT TO:<you@mysmtp.com>
  73. 08-16 15:09:33.470: I/System.out(6314): 250 Accepted
  74. 08-16 15:09:33.470: I/System.out(6314): RCPT TO:<admin@mysmtp.com>
  75. 08-16 15:09:33.478: I/System.out(6314): 250 Accepted
  76. 08-16 15:09:33.478: I/System.out(6314): DEBUG SMTP: Verified Addresses
  77. 08-16 15:09:33.478: I/System.out(6314): DEBUG SMTP: you@mysmtp.com
  78. 08-16 15:09:33.478: I/System.out(6314): DEBUG SMTP: admin@mysmtp.com
  79. 08-16 15:09:33.478: I/System.out(6314): DATA
  80. 08-16 15:09:33.486: I/System.out(6314): 354 Enter message, ending with "." on a line by itself
  81. 08-16 15:09:33.564: I/System.out(6314): Date: Thu, 16 Aug 2012 15:09:30 +0800 (HKT)
  82. 08-16 15:09:33.564: I/System.out(6314): From: me@mysmtp.com
  83. 08-16 15:09:33.564: I/System.out(6314): To: you@mysmtp.com, admin@mysmtp.com
  84. 08-16 15:09:33.564: I/System.out(6314): Message-ID: <1099216984.1.1345100973553.JavaMail.javamailuser@localhost>
  85. 08-16 15:09:33.564: I/System.out(6314): Subject: Record cannot be inserted!
  86. 08-16 15:09:33.564: I/System.out(6314): MIME-Version: 1.0
  87. 08-16 15:09:33.564: I/System.out(6314): Content-Type: multipart/mixed;
  88. 08-16 15:09:33.564: I/System.out(6314): boundary="----=_Part_0_1098789192.1345100970404"
  89. 08-16 15:09:33.564: I/System.out(6314):
  90. 08-16 15:09:33.571: I/System.out(6314): ------=_Part_0_1098789192.1345100970404
  91. 08-16 15:09:33.571: I/System.out(6314): Content-Type: text/plain; charset=us-ascii
  92. 08-16 15:09:33.571: I/System.out(6314): Content-Transfer-Encoding: 7bit
  93. 08-16 15:09:33.571: I/System.out(6314):
  94. 08-16 15:09:33.571: I/System.out(6314): Please insert manually!
  95. 08-16 15:09:33.571: I/System.out(6314): ------=_Part_0_1098789192.1345100970404
  96. 08-16 15:09:33.571: I/System.out(6314): Content-Type: application/octet-stream; name=record.csv
  97. 08-16 15:09:33.571: I/System.out(6314): Content-Transfer-Encoding: 7bit
  98. 08-16 15:09:33.571: I/System.out(6314): Content-Disposition: attachment; filename=record.csv
  99. 08-16 15:09:33.571: I/System.out(6314):
  100. 08-16 15:09:33.571: I/System.out(6314): ABC,HK,A,2012/08/16 10:02, ,
  101. 08-16 15:09:33.571: I/System.out(6314):
  102. 08-16 15:09:33.571: I/System.out(6314): ------=_Part_0_1098789192.1345100970404--
  103. 08-16 15:09:33.571: I/System.out(6314): .
  104. 08-16 15:09:33.611: I/System.out(6314): 250 OK id=1T1uCu-0007Fx-Tu
  105. 08-16 15:09:33.611: I/System.out(6314): QUIT
  106. 08-16 15:09:33.618: I/System.out(6314): 221 web.mysmtp.com closing connection
  107.  
  108. 08-16 15:12:34.353: I/System.out(6876): EHLO localhost
  109. 08-16 15:12:34.361: I/System.out(6876): 250-web.mysmtp.com Hello localhost [202.155.209.250]
  110. 08-16 15:12:34.361: I/System.out(6876): 250-SIZE 52428800
  111. 08-16 15:12:34.361: I/System.out(6876): 250-PIPELINING
  112. 08-16 15:12:34.361: I/System.out(6876): 250-AUTH PLAIN LOGIN
  113. 08-16 15:12:34.361: I/System.out(6876): 250-STARTTLS
  114. 08-16 15:12:34.361: I/System.out(6876): 250 HELP
  115. 08-16 15:12:34.368: I/System.out(6876): DEBUG SMTP: Found extension "SIZE", arg "52428800"
  116. 08-16 15:12:34.368: I/System.out(6876): DEBUG SMTP: Found extension "PIPELINING", arg ""
  117. 08-16 15:12:34.368: I/System.out(6876): DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
  118. 08-16 15:12:34.368: I/System.out(6876): DEBUG SMTP: Found extension "STARTTLS", arg ""
  119. 08-16 15:12:34.368: I/System.out(6876): DEBUG SMTP: Found extension "HELP", arg ""
  120. 08-16 15:12:34.368: I/System.out(6876): DEBUG SMTP: Attempt to authenticate
  121. 08-16 15:12:34.368: I/System.out(6876): AUTH LOGIN
  122. 08-16 15:12:34.384: I/System.out(6876): 334 VXNlcm5hbWU6
  123. 08-16 15:12:34.384: I/System.out(6876): Y2xpZW50YWxlcnRzQHVuaXNlcnZlaXQuY29t
  124. 08-16 15:12:34.392: I/System.out(6876): 334 UGFzc3dvcmQ6
  125. 08-16 15:12:34.392: I/System.out(6876): cEBzc3cwcmQhIUA=
  126. 08-16 15:12:34.400: I/System.out(6876): 235 Authentication succeeded
  127. 08-16 15:12:34.415: I/System.out(6876): DEBUG SMTP: use8bit false
  128. 08-16 15:12:34.415: I/System.out(6876): MAIL FROM:<me@mysmtp.com>
  129. 08-16 15:12:34.431: I/System.out(6876): 250 OK
  130. 08-16 15:12:34.431: I/System.out(6876): RCPT TO:<you@mysmtp.com>
  131. 08-16 15:12:34.470: I/System.out(6876): 250 Accepted
  132. 08-16 15:12:34.470: I/System.out(6876): RCPT TO:<admin@mysmtp.com>
  133. 08-16 15:12:34.486: I/System.out(6876): 250 Accepted
  134. 08-16 15:12:34.486: I/System.out(6876): DEBUG SMTP: Verified Addresses
  135. 08-16 15:12:34.486: I/System.out(6876): DEBUG SMTP: you@mysmtp.com
  136. 08-16 15:12:34.486: I/System.out(6876): DEBUG SMTP: admin@mysmtp.com
  137. 08-16 15:12:34.486: I/System.out(6876): DATA
  138. 08-16 15:12:34.493: I/System.out(6876): 354 Enter message, ending with "." on a line by itself
  139. 08-16 15:12:34.571: I/System.out(6876): Date: Thu, 16 Aug 2012 15:12:32 +0800 (HKT)
  140. 08-16 15:12:34.571: I/System.out(6876): From: me@mysmtp.com
  141. 08-16 15:12:34.571: I/System.out(6876): To: you@mysmtp.com, admin@mysmtp.com
  142. 08-16 15:12:34.571: I/System.out(6876): Message-ID: <1099235248.1.1345101154551.JavaMail.javamailuser@localhost>
  143. 08-16 15:12:34.571: I/System.out(6876): Subject: Record cannot be inserted!
  144. 08-16 15:12:34.571: I/System.out(6876): MIME-Version: 1.0
  145. 08-16 15:12:34.571: I/System.out(6876): Content-Type: multipart/mixed;
  146. 08-16 15:12:34.571: I/System.out(6876): boundary="----=_Part_0_1098789960.1345101152034"
  147. 08-16 15:12:34.571: I/System.out(6876):
  148. 08-16 15:12:34.571: I/System.out(6876): ------=_Part_0_1098789960.1345101152034
  149. 08-16 15:12:34.571: I/System.out(6876): Content-Type: text/plain; charset=us-ascii
  150. 08-16 15:12:34.571: I/System.out(6876): Content-Transfer-Encoding: 7bit
  151. 08-16 15:12:34.571: I/System.out(6876):
  152. 08-16 15:12:34.571: I/System.out(6876): Please insert manually!
  153. 08-16 15:12:34.571: I/System.out(6876): ------=_Part_0_1098789960.1345101152034
  154. 08-16 15:12:34.571: I/System.out(6876): Content-Type: application/octet-stream; name=record.csv
  155. 08-16 15:12:34.571: I/System.out(6876): Content-Transfer-Encoding: 7bit
  156. 08-16 15:12:34.571: I/System.out(6876): Content-Disposition: attachment; filename=record.csv
  157. 08-16 15:12:34.571: I/System.out(6876):
  158. 08-16 15:12:34.571: I/System.out(6876): ABC,HK,A,2012/08/16 10:02, ,
  159. 08-16 15:12:34.571: I/System.out(6876):
  160. 08-16 15:12:34.571: I/System.out(6876): ------=_Part_0_1098789960.1345101152034
  161. 08-16 15:12:34.571: I/System.out(6876): Content-Type: text/plain; charset=us-ascii
  162. 08-16 15:12:34.571: I/System.out(6876): Content-Transfer-Encoding: 7bit
  163. 08-16 15:12:34.571: I/System.out(6876):
  164. 08-16 15:12:34.571: I/System.out(6876):
  165. 08-16 15:12:34.571: I/System.out(6876): ------=_Part_0_1098789960.1345101152034--
  166. 08-16 15:12:34.571: I/System.out(6876): .
  167. 08-16 15:12:34.587: I/System.out(6876): 250 OK id=1T1uFp-0007Ka-TP
  168. 08-16 15:12:34.587: I/System.out(6876): QUIT
  169. 08-16 15:12:34.603: I/System.out(6876): 221 web.mysmtp.com closing connection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement