views:

181

answers:

1

I have the below mail program. The problem is mail program runs successfully but it doesn't send me the emails. The logs say it's mailed successfully. Not sure what might be the problem. Do i need to change the Java Program?

I have the below values set in the application.properties file and these values get read from the program and passed as vector to the send function

mail.smtp.host=excha.testing.com
mail.smtp.techEmail="[email protected]"
mail.smtp.toEmail="[email protected]"
[email protected]
mail.smtp.fromName=Testing test Systems
mailHandler.send(mailingAddress,ccEmailAddress,fromEmailAddress,fromEmailAlias,envName + "::" + " Process", exitMessage + " - " + message))

-----------------------Mail Send Program code pasted below---------

public synchronized boolean send(Vector eMailAddress, Vector ccEmailAddress, String 
fromEmailAddress, String fromEmailAlias, String messageSubject, String messageText)
  {



    try
    {
      Message msg = new MimeMessage(session);
      msg.setSubject(messageSubject);
      msg.setText(messageText);

      InternetAddress addresses[] = new InternetAddress[eMailAddress.size()];
      for (int i = 0; i < eMailAddress.size(); i++ ) {
        addresses[i] = new InternetAddress((String)(eMailAddress.elementAt(i)));
 }
      msg.setRecipients(Message.RecipientType.TO, addresses);

      InternetAddress ccAddresses[] = new InternetAddress[ccEmailAddress.size()];
      for (int i = 0; i < ccEmailAddress.size(); i++ ) {
        ccAddresses[i] = new InternetAddress((String)(ccEmailAddress.elementAt(i)));
 }
      msg.setRecipients(Message.RecipientType.CC, ccAddresses);

      if ((null != fromEmailAddress) && (null != fromEmailAlias))
      {
       msg.setFrom(new InternetAddress(fromEmailAddress, fromEmailAlias));
      } 
      else if ((null != fromEmailAddress) && (null == fromEmailAlias))
      {
       msg.setFrom(new InternetAddress(fromEmailAddress));
      }
      else if ((null == fromEmailAddress) && (null == fromEmailAlias))
      {
       String smtpFromEmail
            = (ApplicationProperties.getApplicationProperties()).getProperty(SMTP_FROM_EMAIL_KEY);
       String smtpFromName
            = (ApplicationProperties.getApplicationProperties()).getProperty(SMTP_FROM_NAME_KEY);
       if (null == smtpFromEmail || "".equals(smtpFromEmail))
       {
         smtpFromEmail = SENDER_EMAIL;
       }
       if (null == smtpFromName || "".equals(smtpFromName))
       {
         smtpFromName = SENDER_NAME;
       }
       msg.setFrom(new InternetAddress(smtpFromEmail, smtpFromName));
      }

      Transport.send(msg);
      cat.debug("Sent message to " + eMailAddress);
      return true;
    } catch (Exception e)
    {
      cat.error("Error sending email", e);
      return false;
    }
  }
+2  A: 

To send mail with Java Mail you need a valid SMTP server and an account in that server.

I'm assuming that the server at excha.testing.com is just swallowing anything you send to it, otherwise I'm failing to see a reason for your program not to work.

Cheers.

Rafael
Thanks a lot . Is there any java Mail sample program that i can try with the same configuration details. would appreciate if you can post any links . This program was written long back.
Arav
@arav: Here is a very basic sample program that uses the JavaMail API: http://www.vipan.com/htdocs/javamail.html
Dougman
Thanks a lot. I will try this program with the same configuration and see whether it;s working
Arav