Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

javax.mail intermittent problem

Posted on 2007-12-03
9
323 Views
Last Modified: 2010-04-21
Hi All,

We are using javax.mail to send email from our JSP application. Recently, we encountered intermittent problem. The mails were being sent from the application but the some of the recipients did not receive their mails. The mails are being sent to each of the recipients one at a time. We knew that the mail was being sent because the application will print "Mail sent successfully" otherwise it will print "Mail sent failed".

What is the likely cause of the problem? Thanks.


I have attached a sample code of sending mail.
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    
    public class SendApp {
        public static void send(String smtpHost, int smtpPort,
                                String from, String to,
                                String subject, String content)
                throws AddressException, MessagingException {
          
            try {
                // Create a mail session
                java.util.Properties props = new java.util.Properties();
                props.put("mail.smtp.host", smtpHost);
                Session session = Session.getDefaultInstance(props, null);
    
                // Construct the message
                Message msg = new MimeMessage(session);
                msg.setFrom(new InternetAddress(from));
                msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
                msg.setSubject(subject);
                msg.setText(content);
    
               // Send the message
               Transport.send(msg);
               System.out.println("\nMail sent Successfully to "+to.trim() + " email: "+subject.trim()+".");
 
           } catch (Exception e) {
		e.printStackTrace();
			
						System.out.println("\nMail sent FAILED to "+to.trim() + " email: "+subject.trim()+".");
	   }
 
        }
    
        public static void main(String[] args) throws Exception {
            // Send a test message
            send("hostname", "joe@smith.com", "sue@smith.com",
                 "re: dinner", "How about at 7?");
        }
    }

Open in new window

0
Comment
Question by:rospcc
9 Comments
 
LVL 13

Expert Comment

by:kawas
ID: 20400847
Could be spam filters ... Do the same ones fail all of the time?
0
 

Author Comment

by:rospcc
ID: 20400964
No, it was different ones. My application has two different types of emails. The two types are one with attachment and one without. The code snippet that i showed earlier is used to send mail without attachment. Most of the mails that failed are those with attachment.
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 20401218
have u checked for bounces
and if you have access to the smtp server check its queues/logs
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 35

Expert Comment

by:TimYates
ID: 20401870
Can you post the code for the mails that failed?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 20401874
Actually, I agree more with objects...  The sendmail logs will probably be the first place to check...
0
 

Author Comment

by:rospcc
ID: 20408574
sorry ...but where can i check the sendmail logs?
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 200 total points
ID: 20410228
On our linux system, they are located at:

  /var/log/maillog

Tim
0
 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 100 total points
ID: 20415268
it depends on the host that you are using... if its connecting an outlook/lotus server , then these servers will have a que where you can check the logs

In short: whatever SMTP host you are connecting to, will have logs of the mails going thru it.
0
 

Author Closing Comment

by:rospcc
ID: 31412515
They restarted the SMTP server, and the mails can be sent out successfully again after that.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Glassfish admin console not working 1 32
java imports not found 4 24
Java syntax, or is it Selenium 6 30
web project error add remove 1 27
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question