I have the below code which right now does just what i need (send a text message to a cell phone using java).
Now my question is a little more specific, and I am not really sure what it entails or if it is even possible.
The question is as follows:
1 – When I send this e-mail, each time a generic (temporary?) sender is created (presumably on the gmail side) that looks always something like "1 (410) 000-00x", where x appears to iterate up/down (I have only done a couple tests). Now, this code below is part of a real time intraday e-mailing mechanism to communicate data to a human, for them to take a certain action.
2 – Because of this, it would be optimal to have the sender be my sample abc@gmail.com but this does not happen. Is there a way to force this to occur? Should I use something other than gmail?
Any pointers are appreciated.
NOTE:
I think this may come up so I will just say now: the action is EXTREMELY time sensitive. With this, e-mail is not quite responsive enough, while text messages are immediately received. I agree sending an e-mail would immediately solve the problem.
public static void sendIT() throws AddressException, MessagingException, javax.mail.MessagingException
{
String host = "smtp.gmail.com";
String from = "abc@gmail.com";
String pass = "test";
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true"); // added this line
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
String[] to = {"5555555555@txt.att.net"};
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = new InternetAddress[to.length];
//message.setFileName(g.destFileTracker);
// To get the array of addresses
for( int i=0; i < to.length; i++ ) { // changed from a while loop
toAddress[i] = new InternetAddress(to[i]);
}
System.out.println(Message.RecipientType.TO);
for( int i=0; i < toAddress.length; i++) { // changed from a while loop
message.addRecipient(Message.RecipientType.BCC, toAddress[i]);
}
message.setSubject("Activity");
message.setText("test");
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
You should try using the mms gateway rather than the txt gateway. The mms gateway will keep the email address. So instead of being txt.att.net it will be mms.att.net.
If this is time sensitive though, you should probably stick with a SMS solution and go third party since I find MMS isn’t as reliable with speed.