on 11-01-2007 7:08 PM
Hi,
I am trying to send a mail from a java application using java mail api and my mail server is exchange server.please find the code which i used
try{
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", "edison.Prosofthq.com");
props.put("mail.smtp.auth", "true");
// Get session
Authenticator loAuthenticator = new MailAuthenticator();
Session session = Session.getInstance(props, loAuthenticator);
// Define message
MimeMessage message =
new MimeMessage(session);
message.setFrom(
new InternetAddress("bala.duvvuri@prosoftcyberworld.com"));
message.addRecipient(
Message.RecipientType.TO,
new InternetAddress("balu_duvvuri@yahoo.com"));
message.setSubject(
"Hello JavaMail Attachment");
// create the message part
MimeBodyPart messageBodyPart =
new MimeBodyPart();
//fill message
messageBodyPart.setText("Hi");
/*Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(pdf.toString(), "application/pdf")));
messageBodyPart.setFileName("Answers.pdf");
multipart.addBodyPart(messageBodyPart);*/
// Put parts in message
//message.setContent(multipart);
// Send the message
Transport.send( message );
}
catch(Exception ex){
System.out.println("ddd"+ex.getMessage());
do {
if (ex instanceof SendFailedException) {
SendFailedException sfex = (SendFailedException) ex;
Address[] invalid = sfex.getInvalidAddresses();
if (invalid != null) {
for (int i = 0; i < invalid.length; i++) {
System.out.println("Invalid address: " +
invalid<i>);
}
}
Address[] validUnsent =
sfex.getValidUnsentAddresses();
if (validUnsent != null) {
for (int i = 0; i < validUnsent.length; i++) {
System.out.println("Valid unsent address: " +
validUnsent<i>);
}
}
Address[] validSent = sfex.getValidSentAddresses();
if (validSent != null) {
for (int i = 0; i < validSent.length; i++) {
System.out.println("Valid sent address: " +
validSent<i>);
}
}
}
if (ex instanceof MessagingException) {
ex = ((MessagingException) ex).getNextException();
} else {
ex = null;
}
} while (ex != null);
}
}
But i am getting the following exception
<b>
Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550 5.7.1 Unable to relay for balu_duvvuri@yahoo.com
Invalid address: balu_duvvuri@yahoo.com
Invalid address: balu_duvvuri@yahoo.com</b>
it is saying <b>to address</b> is invalid.
<b>I did check with my mail admin and added my ip address to the acl list of the exchange server .still i am getting the same problem.</b>
Any pointers on this will be rewarded with points
Hello Bala,
if you want to send an email with an smtp server with authentification you must use this code:
if(auth)
{
Transport transport = session.getTransport("smtp");
transport.connect(smtpHost,smtpLogin,smtpPassword);
message.saveChanges();
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
else
Transport.send(message);
Best regards,
Mathieu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The error you face is an SMTP error, that tells you, that the Exchange server is not allowing you to send mail through it to yahoo.com.
Is your <b>sender</b>address a valid one and does your Exchange server allow you to send via SMTP from this address to an external one?
--
Markus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.