• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
  • Himai Minh
  • Carey Brown
  • salvin francis

sending email to hotmail account using javamail API

Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I need to write a program for sending email to some Hotmail account. I am using javamail API. I am totally new to javamail API and writing email programs.

Here is a part of my program code ( which I got from one of demo folder of javamail API ):

String from = "xxx@hotmail.com";
String url = null;
String mailhost = null;
String mailer = "smtpsend";
String protocol = null, host = null, user = null, password = null;
String record = null; // name of folder in which to record mail
boolean debug = false;
boolean verbose = false;
boolean auth = false;
SMTPTransport t=null;

Properties prop = System.getProperties();
prop.put("mail.smtp.host", mailhost);
prop.put("mail.smtp.auth", "true");

// Get a Session object
Session session = Session.getInstance(prop, null);

// construct the message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(textTo.getText(), false));
msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse(textCc.getText(), false));
msg.setHeader("X-Mailer", mailer);
msg.setSentDate(new Date());
t = (SMTPTransport)session.getTransport("smtp");
t.connect(mailhost, user, password); // because author is true

System.out.println("got connected");

t.sendMessage(msg, msg.getAllRecipients());

System.out.println("message sent");

}catch(MessagingException ms){System.out.println(ms);}
if (verbose) System.out.println("Response: " + t.getLastServerResponse());
try{ t.close(); }catch(MessagingException m){System.out.println(m);}

System.out.println("\nMail was sent successfully.");


In the above code I want to know
- what are ' mailhost and host ' and what value I should put there in case I want to send the email to Hotmail account?
- Somewhere I read hotmail doesn't uses smtp for sending emails. In that case the code I am writing above is wrong. What should I change?
- Also If I should use some smtp server to send emails to hotmail account or I can just send emails without it.

I might be asking some silly questions but please answer me.

Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use a Server to send your mails.

the JAVA MAIL API's just give an abstraction and allows you to connect to the SMTP Server and send mails through it, without knowing the underlying technical information.
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks prince for answering me. I have another question.

At present I used the smtp server running in my office. But that will work only when I am in office. I want to know if there are some other smtp server freely available to send emails.
Remember to always leap before you look. But always take the time to smell the tiny ads:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic