[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Java Mail Transport.send(message) issue.....

Posted on 2002-06-01
3
Medium Priority
?
1,582 Views
Last Modified: 2013-11-24
Hi,
I've a problem with Java Mail. In my application I am trying to send a mail with an attachment to the user who clicked the product download link in our website.
The code is developed in Windows 2000 Professional env. Its been successfully tested in the local Solaris also. But, our website is hosted on firstlink.com's webserver. So, the smtpHost and smtpPort nos are changed as per the smtp.firstlink.com configuration settings and hosted in the webserver. Nothing else is modified in my code. But, its throwing NumberFormatException while executing Transport.send();
The code snippet is given below for the review....


 
 public class MailDispatcher{
 
    private String from           = "sales@xxx.com";
    private String to             = "user@xxx.com";
    private String subject        = "License Key file attached";
    private String smtpHost;
    private String smtpPort;
    private String mailMessage    = "Message for client";
    private String signature;
    private String ConfigFile     = "ConfigFile";
    private String DefaultConfigFile   = "download.properties";
    private String fileAttachmentName  = null;
    private static PropertyResourceBundle resource;
    public static final String Mailer = "website.mailer";
    private String logfile;
    private String errorfile;
   
   
   /**
    *  This is the default constructor
    *  Loads   properties from from specified by "ConfigFile" parameter.
    *
    */
    public MailDispatcher() {

         try {

              InputStream inStream = this.getClass().getResourceAsStream("download.PROPERTIES");
              if (inStream == null) {
                  throw new Exception();
              }

              resource = new PropertyResourceBundle(inStream);
              from = resource.getString("from");
              smtpHost = resource.getString("smtpHost");
              smtpPort = resource.getString("smtpPort");
              mailMessage = resource.getString("MailMessage");
              signature = resource.getString("Signature");
              subject = resource.getString("subject");
              logfile = resource.getString("logfile");
              errorfile = resource.getString("errfile");
              fileAttachmentName = resource.getString("attachmentfile");
             
         } catch (Exception ex) {
             Logger.log(Mailer, Logger.Error, new LogMessage(ex));
             ex.printStackTrace();
         }
    }


 
   /**
    * This method is for sending mail to the registered client after product has downloaded successfully.
    * This mail contain the key code for installing the product.
    *
    * @param
    * @return boolean  trueorfalse
    */
    public synchronized boolean sendMail() {

         Properties props = System.getProperties();
         props.put("mail.smtp.host", smtpHost);
         props.put("mail.smtp.port", smtpPort);
         Session session = Session.getInstance(props, null);
         try {              
              // create a message
              message.setFrom(new InternetAddress(getFrom()));
              InternetAddress[] address = {new InternetAddress(to)};
              message.setRecipients(Message.RecipientType.TO, address);
              message.setSubject(subject);
           
              // create and fill the first message part
              MimeBodyPart mbp1 = new MimeBodyPart();
              if (signature != null) {
                mailMessage = mailMessage + "\n\n" + signature;
              }
              mbp1.setText(mailMessage);
              // create the Multipart and its parts to it
              Multipart mp = new MimeMultipart();
              mp.addBodyPart(mbp1);
           
              // attach the file to the message
              MimeBodyPart mbp2 = new MimeBodyPart();
              FileDataSource fds=new FileDataSource(fileAttachmentName);
              mbp2.setDataHandler(new DataHandler(fds));
              mbp2.setFileName("ABCD.doc");//fileAttachmentName
              mp.addBodyPart(mbp2);
           
              // add the Multipart to the message
              message.setContent(mp);
              // set the Date: header
              message.setSentDate(new Date());
              // send the message
              Transport.send(message);
              return true;

         }  catch (Exception e) {
             
              e.printStackTrace();
         }
    }

}


The Exception received is....

java.lang.NumberFormatException: 25
      at java.lang.Integer.parseInt(Integer.java:423)
      at java.lang.Integer.parseInt(Integer.java:463)
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:78)
      at javax.mail.Service.connect(Service.java:221)
      at javax.mail.Service.connect(Service.java:127)
      at javax.mail.Service.connect(Service.java:83)
      at javax.mail.Transport.send0(Transport.java:148)
      at javax.mail.Transport.send(Transport.java:73)
      at com.objectfrontier.website.download.util.MailDispatcher.sendMail(MailDispatcher.java:292)
      at download.jsp.page.download.EmailVerifierAction_1._jspService(EmailVerifierAction_1.java:331)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java)
      at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
      at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
      at org.apache.tomcat.core.Handler.service(Handler.java:235)
      at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
      at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
      at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
      at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Interceptor.java:341)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
      at java.lang.Thread.run(Thread.java:484)

Does anybody have any clue for this???
0
Comment
Question by:Bhogi
[X]
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
  • 2
3 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 7050580
Have you tried to do this:
smtpPort = resource.getString("smtpPort");

int port = Integer.parseInt(smtpPort);


only to check whether the smtpPort can be parsed?
If this line throw NumberFormatException - I also suggest you to check the length of the smtpPort string.
0
 

Accepted Solution

by:
JavaRam earned 600 total points
ID: 7050744
Hi,
The NumberFromatException which u r getting is while converting the String value of the port number into integer. May be there is invalid characters or blank places present while specifying the smtpport no. As u said u r reading the port no from the properties file, after reading it, u can call trim() method to remove the leading/trailing blank spaces.
Hope it helps solving ur issue.
...$Javaram$...
0
 

Expert Comment

by:JavaRam
ID: 7055866
Bhogi,
Did u try with my suggestion?? Let us know the trial result.
...$Javaram$...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 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