aspose file tools
The moose likes Other JSE/JEE APIs and the fly likes sending mail with JavaMail and Exchange Server Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "sending mail with JavaMail and Exchange Server" Watch "sending mail with JavaMail and Exchange Server" New topic
Author

sending mail with JavaMail and Exchange Server

Ruud Steeghs
Ranch Hand

Joined: Jul 09, 2001
Posts: 56
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

Joined: Jul 09, 2001
Posts: 56
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.
 
 
subject: sending mail with JavaMail and Exchange Server
 
Threads others viewed
how to send email from java program
how to send mail using gmail server
sending email in java not working
javax.mail package
Help me please, JavaMail
developer file tools