9 Replies Latest reply: Apr 23, 2013 4:23 PM by Bshannon-Oracle RSS

    550 Unable to relay NTML

    user10601354
      Hi,

      I'm trying to send an email from MsExhange with NTML Auth.

      the problem is that JAVAMAIL return this error:

      javax.mail.SendFailedException: Invalid Addresses;
      nested exception is:
           javax.mail.SendFailedException: 550 5.7.1 Unable to relay


      The code is:

      public static void SendMailSSL(String SMTPHost,
      String SMTPPort,
      String SMTPDomain,
      String SMTPUsern,
      String SMTPUserp,
      String SMTPAuth,
      String from,
      String to,
      String cc,
      String bcc,
      String subject,
      String body,
      oracle.sql.BLOB attachmentData,
      String attachmentType,
      String attachmentFileName)

      {
      int rc = 0;
      String timeOut = "3000";
      String[] arr;
      int portMsg = Integer.parseInt(SMTPPort);
      int auth = Integer.parseInt(SMTPAuth);

      try
      {
      Properties props = System.getProperties();
      props.put("mail.smtp.host", SMTPHost);
      props.put("mail.smtp.port", portMsg);
      props.put("mail.smtp.timeout", timeOut);

      if (auth == 1) {
      props.setProperty("mail.smtp.auth", "true");
      }

      Session session = Session.getDefaultInstance(props, null);
      session.setDebug(true);

      Message msg =
      new MimeMessage(session);

      msg.setFrom(new InternetAddress(from));

      if (to != "_noRecipients_")
      {
      arr = to.split(";");
      for(int i=0; i<arr.length; i++){
      msg.addRecipient(Message.RecipientType.TO,
      new InternetAddress(arr));
      }
      }

      if (cc != null)
      {
      arr = cc.split(";");
      for(int i=0; i<arr.length; i++){
      msg.addRecipient(Message.RecipientType.CC,
      new InternetAddress(arr[i]));
      }
      }

      if (bcc != null)
      {
      arr = bcc.split(";");
      for(int i=0; i<arr.length; i++){
      msg.addRecipient(Message.RecipientType.BCC,
      new InternetAddress(arr[i]));
      }
      }

      if ( subject != null & subject.length() > 0 )
      msg.setSubject(subject);
      else msg.setSubject("(no subject)");

      msg.setSentDate(new Date());

      if (attachmentData != null)
      {
      MimeBodyPart mbp1 = new MimeBodyPart();
      mbp1.setContent((body != null ? body : ""),"text/html");
      mbp1.setDisposition(Part.INLINE);

      MimeBodyPart mbp2 = new MimeBodyPart();
      String type =
      (attachmentType != null ? attachmentType : dftMime);

      String fileName = (attachmentFileName != null ?
      attachmentFileName : dftName);

      mbp2.setDisposition(Part.ATTACHMENT);
      mbp2.setFileName(fileName);
      mbp2.setHeader("Content-Type", type);

      mbp2.setDataHandler(new
      DataHandler(new BLOBDataSource(attachmentData, type))
      );
      mbp2.setHeader("Content-Transfer-Encoding", "base64");

      MimeMultipart mp = new MimeMultipart();
      mp.addBodyPart(mbp1);
      mp.addBodyPart(mbp2);
      msg.setContent(mp);
      }
      else
      {
      msg.setContent((body != null ? body : ""),"text/html");
      }

      Transport transport = session.getTransport("smtp");
      transport.connect(SMTPHost, portMsg,SMTPUsern, SMTPUserp);

      transport.sendMessage(msg, msg.getAllRecipients());
      transport.close();

      rc = 1;
      } catch (Exception e)
      {         
      throw new RuntimeException(e);
      }
      }

      Any idea

      Thanks