1

Web アプリケーションからメールを送信しようとすると、次の例外が発生しました。

com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.1 Missing 
or literal domains not allowed

以下のコードのようなプロパティを使用しています。

Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.verizon.net");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");

また、認証方法を使用して、ユーザー名とパスワードを使用してユーザーを認証します。

認証されている場合にのみ成功メッセージを受け取りました。という行に行くと例外が発生しましたtransport.sen(message)

    this is my full code..



try {

            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(
                    to));
//          message.addRecipient(Message.RecipientType.CC, new InternetAddress(
//                  cc));
//          message.addRecipient(Message.RecipientType.BCC,
//                  new InternetAddress(bcc));
            message.setSubject("TEST...!!!!!!!");

             Multipart multipart = new MimeMultipart();

             BodyPart messageBodyPart = new MimeBodyPart();
             messageBodyPart
             .setText("Dear Sir, Mail Testing");
             multipart.addBodyPart(messageBodyPart);


             messageBodyPart.setText("Hao test");
            message.setText("Kader here");
             message.setContent(multipart);


             MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
                mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
                mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
                mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
                mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
                mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
                CommandMap.setDefaultCommandMap(mc);
            Transport transport = session.getTransport();

            transport.connect();
            Transport.send(message);
            transport.close();


            System.out.println("Sent message successfully....");
        } catch (MessagingException mex) {
            mex.printStackTrace();
        }
4

2 に答える 2

1

一部のメールサーバーは、クライアントのログ記録時にユーザー名にドメイン名を自動的に追加する可能性がありますが、一部のサーバーは追加しないため、認証に失敗します。

于 2013-04-27T07:16:56.600 に答える
0
Try this code  :-

MailUtil.java
------------ 
package com.test;

import java.io.UnsupportedEncodingException;  
import java.util.Properties;  
import java.util.logging.Level;  
import java.util.logging.Logger;  
import javax.mail.Authenticator;  
import javax.mail.Message;  
import javax.mail.MessagingException;  
import javax.mail.PasswordAuthentication;  
import javax.mail.Session;  
import javax.mail.Transport;  
import javax.mail.internet.InternetAddress;  
import javax.mail.internet.MimeMessage;  

/**
   * Please test with your GMAIL
   * @author Jamsheer T
   * +91-9846716175
   *
   */

public class MailUtil {  

private String SMTP_HOST = "smtp.gmail.com";  
private String FROM_ADDRESS = "jamsheer568@gmail.com";  //Give Your  gmail here 
private String PASSWORD = "***********";  //Give Your password here
private String FROM_NAME = "Jamsheer T";  

  public boolean sendMail(String[] recipients, String[] bccRecipients, String subject, 

  String message) {  
    try {  
        Properties props = new Properties();  
        props.put("mail.smtp.host", SMTP_HOST);  
        props.put("mail.smtp.auth", "true");  
        props.put("mail.debug", "false");  
        props.put("mail.smtp.ssl.enable", "true");  
        props.put("mail.smtp.starttls.enable","true");

        Session session = Session.getInstance(props, new SocialAuth());  
        Message msg = new MimeMessage(session);  

        InternetAddress from = new InternetAddress(FROM_ADDRESS, FROM_NAME);  
        msg.setFrom(from);  

        InternetAddress[] toAddresses = new InternetAddress[recipients.length];  
        for (int i = 0; i < recipients.length; i++) {  
            toAddresses[i] = new InternetAddress(recipients[i]);  
        }  
        msg.setRecipients(Message.RecipientType.TO, toAddresses);  


        InternetAddress[] bccAddresses = new InternetAddress[bccRecipients.length];  
        for (int j = 0; j < bccRecipients.length; j++) {  
            bccAddresses[j] = new InternetAddress(bccRecipients[j]);  
        }  
        msg.setRecipients(Message.RecipientType.BCC, bccAddresses);  

        msg.setSubject(subject);  
        msg.setContent(message, "text/plain");  
        Transport.send(msg);  
        return true;  
    } catch (UnsupportedEncodingException ex) {  
        ex.printStackTrace();

        Logger.getLogger(MailUtil.class.getName()).log(Level.SEVERE, null, ex);  
        return false;  

    } catch (MessagingException ex) {  
        ex.printStackTrace();

        Logger.getLogger(MailUtil.class.getName()).log(Level.SEVERE, null, ex);  
        return false;  
    }  
}  

class SocialAuth extends Authenticator {  


    protected PasswordAuthentication getPasswordAuthentication() {  

        return new PasswordAuthentication(FROM_ADDRESS, PASSWORD);  

    }  
   }  
  }

 Main.java
 ----------------
 package com.test;


 public class Main {  

   public static void main(String[] args) {  
   String[] recipients = new String[]{"example1@gmail.com"};  //To
   String[] bccRecipients = new String[]{"example2@gmail.com"};  //Bcc
   String subject = "Test Mail";  //Subject
   String messageBody = "Hi how  r  u?????";  //Body


      System.out.print("Result"+new MailUtil().sendMail(recipients, bccRecipients, 

  subject, messageBody));

   }  
   }  
于 2013-08-30T06:16:11.447 に答える