views:

38

answers:

3

Hi, Im developing a simple Email Application, I have done sending email using java with following code.`

public class SendMail {

    public SendMail() throws MessagingException {

        String host = "smtp.gmail.com";
        String Password = "mnmnn";
        String from = "[email protected]";
        String toAddress = "[email protected]";
        String filename = "C:/Users/hp/Desktop/Write.txt";
        // Get system properties
        Properties props = System.getProperties();
        props.put("mail.smtp.host", host);
        props.put("mail.smtps.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        Session session = Session.getInstance(props, null);

        MimeMessage message = new MimeMessage(session);

        message.setFrom(new InternetAddress(from));

        message.setRecipients(Message.RecipientType.TO, toAddress);

        message.setSubject("JavaMail Attachment");

        BodyPart messageBodyPart = new MimeBodyPart();

        messageBodyPart.setText("Here's the file");

        Multipart multipart = new MimeMultipart();

        multipart.addBodyPart(messageBodyPart);

        messageBodyPart = new MimeBodyPart();

        DataSource source = new FileDataSource(filename);

        messageBodyPart.setDataHandler(new DataHandler(source));

        messageBodyPart.setFileName(filename);

        multipart.addBodyPart(messageBodyPart);

        message.setContent(multipart);

        try {
            Transport tr = session.getTransport("smtps");
            tr.connect(host, from, Password);
            tr.sendMessage(message, message.getAllRecipients());
            System.out.println("Mail Sent Successfully");
            tr.close();

        } catch (SendFailedException sfe) {

            System.out.println(sfe);
        }
    }
}` 

I want to develope SMSAlert application using java. I want to get sms alerts to my number whenever i get mail. Is it possible in java. Thanks in advance.

A: 

There have been quite a lot of posts about this already.

My advice is to go through a third party provider such as aspsms.com and then to use their API (web service or wathever).

This one has a .Net API, but with Java, you should be able to use the SOAP webservice.

JSmaga
A: 

See this answer

This discussion thread about Kannel and SMS Gateways might be of some help.

zengr
A: 

An easy and free way to accomplish this is to send an email to your sms inbox.

Each provider has a different domain, but say for sprint emails sent to [mynumber]@messaging.sprintpcs.com will be texted to me.

There doesn't seem to be much of a delay, we have monitoring processes that send out emails and texts this way on error conditions and they arrive simultaneously.

Of course if your recipients are spread across multiple networks maintaining this sort of system gets trickier, because you've got to look up the email domains.

anq