Sending mail with authentication to Exchange Server 2007
843834Jan 19 2010 — edited Jun 17 2010Hello all,
I heard that Exchange server 2007 has a differernt mechanism of authentication.
I am using a simple program to send a test mail to my outlook inbox (exchange server 2007). But it asks for auhentication when i ran it.
Then i tried giving my username and password. But i am still facing the same problem.
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Client was not authenticated
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1668)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1207)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:735)
at javax.mail.Transport.send0(Transport.java:191)
at javax.mail.Transport.send(Transport.java:120)
at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:64)
at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:25)
I hear that exchange server 2007 has different way of giving username.(with domain name\username)
I tried the same, But i am still getting the same error.
Please help me.
I am adding the price of code:
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class SendingEmail
{
public static void main(String [] args)
{
String to = " vis.v@ap.abc.com";
String from = "sun.c@ap.abc.com";
String host = "43.11.11.11";
String user="ap\\pmtuser";
String pass="password123";
Properties properties = System.getProperties();
System.out.println(user);
// Setup mail server
properties.put("mail.smtp.host", host);
properties.put("mail.user", user);
properties.put("mail.password", pass);
//properties.setProperty("mail.smtp.port", "25");
properties.put("mail.smtp.auth", "true");
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("This is the Subject Line!");
message.setText("This is actual message");
Transport.send(message);
//System.out.println("Sent message successfully....");
}catch (Exception mex) {
mex.printStackTrace();
}
}
}