Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The following method doesn't send emails to "outside" addresses

Status
Not open for further replies.

thelordoftherings

Programmer
May 16, 2004
616
IL
Hello,

I am using this method to send an email:

public boolean sendMail(String from, String to, String subject, String body)
{
try
{
InitialContext ctx = new InitialContext();
Session sess = (Session) javax.rmi.PortableRemoteObject.narrow(ctx.lookup("java:comp/env/mail/MailSession"), Session.class);
MimeMessage msg = new MimeMessage(sess);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, extractRecipientAddresses(to));
msg.setSubject(subject, "UTF-8");
msg.setContent(body, "text/plain;charset=UTF-8");
msg.saveChanges();
Transport tr = sess.getTransport("smtp");
tr.connect(HOST, "", "");
Address[] address = msg.getAllRecipients();
tr.sendMessage(msg, address);
tr.close();
return true;
}
catch (Exception e)
{
System.err.println(e.getMessage());
return false;
}
}

The HOST is our exchange hostname inside the organization.
The problem is that this method only sends mails to email addresses inside our organization. If, for example, I would like to use it to send an email to an account outside the organization, such as Hotmail, the sending doesn't succeed. Any ideas why?
 
Thats a question for your MTA admin - its nothing to do with Java. With that code, you are just dumping email into your MTA's outbound queue.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hey sedj,
This is exactly what I think too, though he insist that the problem is with the code so I wanted to get a second opinion. 10X alot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top