Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sending mail with JavaMail and Exchange Server  RSS feed

 
Ruud Steeghs
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
At work I have to send an email using Microsoft Exchange Server.
I have succeeded sending mail at home using smtp-protocol. However, this does not work in my projec. Does anyone have an idea on what property to set, for "mail.smtp.host" is not the right property?
Below is the code that works for me at home. (taken from sun tutorial)
Cheers,
Ruud.

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class SendMail
{
public static void main (String args[]) throws Exception
{
String host = "mail.notreal.com";
String from = "from-name@provider.com";
String to = "to-name@provider.com";
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props,null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
System.out.println(" setting subject and message ");
message.setSubject("hi ");
message.setText("how r u");
Transport.send(message);
System.out.println(" sent the message ");
System.out.println(" thanks ");
}
}
 
Ruud Steeghs
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem solved! Apparently, I was using the wrong smtp-host.
I used the smtp-host that I found in my Outlook, but I had to use another one.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!