Mail interno vai, mas o externo não. O que ocorre?

1 resposta
L

Pessoal,

Desenvolvi a rotina abaixo que envia mail através da classe commons (org.apache.commons.mail.HtmlEmail).
O problema é, quando envio mail interno isto funciona, mas quando tento mandar para um mail externo não funciona.
Só para informar, estou utilizando o exchange 2003.

Se funciona para interno significa que está conseguindo autenticar, porque não funciona com o externo?

Alguém sabe dizer o que ocorre?
Tem algo haver com o exchange?
:x

public void send(String newSubject, String newBodyHtml, String newBody, String newFailure)
  {
    HtmlEmail email = new HtmlEmail();
    Parameter parameter = new Parameter();
    
    try  
    {   
      if (resultMail.size() > 0)
      {
        bodyHtml = "Teste";
        
        smtpPort     = Integer.parseInt(parameter.getValue("CORMAILPORT"));
        smtpServer   = parameter.getValue("CORMAILSMTP");
        smtpAuth     = parameter.getValue("CORMAILSMTPAUTH");
        smtpAuthUser = parameter.getValue("CORMAILSMTPUSER");
        smtpAuthPass = parameter.getValue("CORMAILSMTPPASS");
        fromMail     = parameter.getValue("CORMAILFROM");
        fromName     = parameter.getValue("CORMAILFROMNAME");
        
        email.setSmtpPort(smtpPort);
        email.setHostName(smtpServer); // o servidor SMTP para envio do e-mail
        email.setFrom(fromMail, fromName); // remetente
        email.setSubject(newSubject);
        email.setHtmlMsg(bodyHtml);
        email.setTextMsg(newBody);
       
        // SMTP with authentication
        email.setAuthentication(smtpAuthUser,smtpAuthPass);
        
        for (int i = 0; i < resultMail.size(); i++)
        {
          emailBean = (MailBean) resultMail.get(i);
          if (ub.notEmpty(emailBean.getToEmail())) {
            email.addTo(emailBean.getToEmail().replaceAll(" ","").replaceAll(",",";")); //destinatário
          }
          if (ub.notEmpty(emailBean.getCcEmail())) {
            email.addCc(emailBean.getCcEmail(), emailBean.getCcName().replaceAll(" ","").replaceAll(",",";")); //destinatário
          }
        }
        
        email.send();
      }
    }

1 Resposta

L

Já achei o problema!

Econtrei o no JavaMail FAQ a resposta conforme abaixo.

Q: When I try to send a message, why do I get javax.mail.SendFailedException: 550 Unable to relay for my-address?
A: This is not a JavaMail problem. This is an error reply from your SMTP mail server. It indicates that your mail server is not configured to allow you to send mail through it. Typically, mail servers for an organization will be configured to allow mail from within the organization to be sent to other addresses within the organization, or to addresses external to the organization. It will also typically allow mail coming from an address external to an organization to be sent to addresses within the organization. What it will typically not allow is mail coming from an address external to the organization to be sent (relayed) to another address also external to the organization. The configuration of the mail server determines whether such relaying is allowed, and which addresses are considered internal vs. external. Often mail servers will require you to authenticate before they will relay messages.

O problema estava no servidor, pois não estava configurado par envio externo. Foi configurado o IP do servidor que permite envio de mail externo e funcionou.

Na verdade eu que estava pensando errado. A API não envia mail pelo exchange, ela é um gerenciador de emails onde utiliza os recursos para envio (mesma porta, usuário, etc.).

Fica aí a dica para quem quiser.

Criado 12 de agosto de 2009
Ultima resposta 13 de ago. de 2009
Respostas 1
Participantes 1