Guest User

Untitled

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