开发者

Java Mail program not working

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="test1@test.com"
mail.smtp.toEmail="test2@test.com"
mail.smtp.fromEmail=test_systems@test.com
mail.smtp.fromName=Testing test Systems
mailHandler.send(mai开发者_StackOverflow社区lingAddress,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;
    }
  }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜