Guest User

Untitled

a guest
Jul 29th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.InetAddress;
  3. import java.util.Properties;
  4. import java.util.Date;
  5. import javax.mail.*;
  6. import javax.mail.internet.*;
  7. import javax.activation.*;
  8.  
  9. public class SMTPSend {
  10.  
  11. public SMTPSend() {
  12. }
  13.  
  14. public void msgsend() {
  15. String username = "YoureIPIPIUsername";
  16. String password = "YourPassword";
  17. String smtphost = "ipipi.com";
  18. String compression = "Compression Option goes here - find out more";
  19. String from = "YoureIPIPIUsername@ipipi.com";
  20. String to = "DestinationPhoneNumber@sms.ipipi.com";
  21. String body = "Your Message";
  22. Transport tr = null;
  23.  
  24. try {
  25. Properties props = System.getProperties();
  26. props.put("mail.smtp.auth", "true");
  27.  
  28. // Get a Session object
  29. Session mailSession = Session.getDefaultInstance(props, null);
  30.  
  31. // construct the message
  32. Message msg = new MimeMessage(mailSession);
  33.  
  34. //Set message attributes
  35. msg.setFrom(new InternetAddress(from));
  36. InternetAddress[] address = {new InternetAddress(to)};
  37. msg.setRecipients(Message.RecipientType.TO, address);
  38. msg.setSubject(compression);
  39. msg.setText(body);
  40. msg.setSentDate(new Date());
  41.  
  42. tr = mailSession.getTransport("smtp");
  43. tr.connect(smtphost, username, password);
  44. msg.saveChanges();
  45. tr.sendMessage(msg, msg.getAllRecipients());
  46. tr.close();
  47. } catch (Exception e) {
  48. e.printStackTrace();
  49. }
  50. }
  51.  
  52. public static void main(String[] argv) {
  53. SMTPSend smtpSend = new SMTPSend();
  54. smtpSend.msgsend();
  55. }
  56. }
Add Comment
Please, Sign In to add comment