aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Java Mail not sending emails when using from WAN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Java Mail not sending emails when using from WAN" Watch "Java Mail not sending emails when using from WAN" New topic
Author

Java Mail not sending emails when using from WAN

ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
HELLO Everyone,
below is my sample code for java mail, my problem is that when my application use to send the email from USA it works fine.
But when someone try to send emails from Outside the USA, i am not receiveing any emails. I dont why. And everyone has the right to access the email Server from even the end user is outside the USA.
The end Users are connected thorugh WAN.
thanks in advance

**********************

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
import javax.mail.Authenticator;


public class EmailClass {
public EmailClass(String emailMsgTxt, String emailSubjectTxt,
String emailFromAddress, String emailList[]) {
try {

Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.host", "myCompanyHostName.com");

Session sess = Session.getInstance(props);
Message msg1 = new MimeMessage(sess);
msg1.setFrom(new InternetAddress(emailFromAddress));

InternetAddress[] addressTo = new InternetAddress [emailList.length];

for (int i = 0; i < emailList.length; i++) {
addressTo[i] = new InternetAddress(emailList[i]);
}

msg1.setRecipients(Message.RecipientType.TO, addressTo);
msg1.setSubject(emailSubjectTxt);
msg1.setText(emailMsgTxt);
msg1.setSentDate(new Date());

Transport.send(msg1);

} catch (Exception e) {
System.out.println(e.getStackTrace());
}

}


}
**************************
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18856
    
    8

You are using that code to send messages, and not everybody receives their messages? Then go and ask the administrator of your SMTP server why that is happening. They should be able to look at server logs and configurations and find out what the problem is.
ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
Thanks Paul for your reply, actually sendig email is works fine form head office i mean where all the servers are reside, but for outside station for example if someone want to send email from Tokyo to me(i am in USA) via WAN, so i am not receieving any email and there is also No Exception i can see in my Log file.
I have asked the same question to my administrator that is there is issue of right invole to access the email server. He said that everyone has the complete rights. That is why i have posted into this forum might get some good advise because my code is pretty much simple and straight forward.

Quick question for knowledge that we are also ysing firewall so this can be an issue Paul or i am going wrong direction.

thanks anyway
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18856
    
    8

You are asking why you can't receive e-mail? The code you posted there is for sending e-mail, so it can't have anything to do with the problem.
ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
Sorry for misunderstanding, i am saying that when ever my end user from outside USA, submit any request so while submitting new request it will inform me via email, so they send email but i am not recieving any email from their side, but on the other hand, if i submit any request so it will send email so my boss recieving this email which i send because i am in USA. but i dont know why the same code is not working from outside usa and thrwoing no exception.
thanks for your reply
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18856
    
    8

If the other users aren't configured so that they are allowed to relay (it sounds like they are in a different domain from you) then their mail servers are allowed to drop your message without sending it and without throwing an exception to your code. Somebody would have to look at the setup of their SMTP server to see exactly what is happening. That somebody should be the administrator of that server.

You might have to add authentication to your code, but I don't think you should solve the problem until you know what it is. The SMTP administrators are the ones most likely to identify the problem.
ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
thanks Paul for your quick response, but we have the same domain, because we all are in the same company. so we have the same domain like abc@company.com so endUser@company.com

can you give me that what should i have to ask to administrator to check.

once again thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18856
    
    8

Explain to the administrator what you see happening and what you want to happen instead. Be prepared to do whatever it is that isn't working correctly when the administrator asks you to do that. This is a networking problem. If neither you nor the administrator can solve it then you need to call in somebody who understands networks better. Don't ask me to explain your problem to the administrator because I don't know what it is. It's just obvious that it's something to do with the network.
ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
thanks alot Paul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Mail not sending emails when using from WAN