2012-06-29 4 views
3

를 사용하여 :어떻게 잘못된 프로토콜을 보정 : 널 보내는 메일을 내가 이런 식으로 메일을 보내려고 javax.mail

javax.mail.NoSuchProviderException: Invalid protocol: null 
    at javax.mail.Session.getProvider(Session.java:440) 
    at javax.mail.Session.getTransport(Session.java:659) 
    at javax.mail.Session.getTransport(Session.java:640) 
    at javax.mail.Session.getTransport(Session.java:626) 
    at Mail.sendMail(Mail.java:151) 

: 행 Transport transport...

Properties props = new Properties(); 
props.setProperty("mail.transport.protocol", "smtp"); 
props.setProperty("mail.host", "out.alice.it"); 
props.setProperty("mail.user", "[email protected]"); 
props.setProperty("mail.password", "*****"); 
Session mailSession = Session.getDefaultInstance(props, null); 
Transport transport = mailSession.getTransport(); 
MimeMessage message = new MimeMessage(mailSession); 
message.setFrom(new InternetAddress("Host", "Name")); 

내가이 오류를 검색 어떻게 해결할 수 있습니까? 누군가 나를 도울 수 있습니까? 감사!! :)

편집 : 내가 주를 작성하고 메일을 보낼 그 방법을 실행하는 경우

, 그것은 좋은 작품!

ArrayList<String> reply = new ArrayList<String(); 
for(Message message:messages) { 
    if(message.getFrom()[0].toString().equals("aMail")){ 
     reply.add(message.getFrom()[0].toString()); 
    } 
} 
store.close(); 
for(String mail : reply){ 
    sendMail(mail); // ERROR AGAIN! 
} 

아주 이상한 : 나는 그래서 난이 방법으로 편집받은 편지함의 메일을 가져 가게를 연 원인 예외 @ 卜 @를 생각

Properties properties = System.getProperties(); 
properties.setProperty("mail.store.protocol", "imap"); 
Session session = Session.getDefaultInstance(properties, null); 
Store store = session.getStore("pop3"); 
store.connect("pop3.domain.it", "[email protected]", "****"); 
Folder inbox = store.getFolder("inbox"); 
FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false); 
inbox.open(Folder.READ_ONLY); 
Message messages[] = inbox.search(ft); 
for(Message message:messages) { 
    if(message.getFrom()[0].toString().equals("aMail")){ 
     sendMail(message.getFrom()[0].toString());//Error! 
    } 
} 

: 내 문제는 내가 메일 폴더로 메일을 읽은 후 @ 卜 @ .... THIS WAY에 용해

:이 열 변형

Session mailSession = Session.getDefaultInstance(props, null); 

Session mailSession = Session.getInstance(props); 
+0

그래, 오직 하나의 디폴트'Session' 인스턴스 만 존재합니다. 다른 인증자를 사용하여 가져온 후 기본값을 가져 오려고하면 오류가 표시되면서 실패합니다. – dkarp

+0

나를 위해 솔루션은 여기에 http://stackoverflow.com/questions/17590762/javax-mail-nosuchproviderexception-invalid-protocol-null – Madhu

답변

2

에 다른 방법을 시도 할 수 있습니다 :

Properties props = new Properties(); 
props.setProperty("mail.transport.protocol", "smtp"); 
props.setProperty("mail.smtp.host", "out.alice.it"); 
props.setProperty("mail.smtp.auth", "true"); 
final PasswordAuthentication auth = new PasswordAuthentication(smtpUser, stmpPassword); 
Session mailSession = Session.getDefaultInstance(props, new Authenticator() { 
    @Override 
    protected PasswordAuthentication getPasswordAuthentication() { return auth; } 
}); 
MimeMessage message = ....; 
// compose the message 
Transport.send(message); 
+0

나에게이 예외가 발생했습니다 : java.lang.SecurityException : 기본 세션 거부 액세스 – JackTurky

+0

참조하십시오 편집 pls .. :) – JackTurky

+0

내가 왜하지만 메인 클래스를 통해 이메일을 보낼 때 그것은 문제가 아니지만 jsf 응용 프로그램을 통해 메일을 보낼 때 프로토콜 smtp를 설정해야합니다 모르겠어요. – gesus

1

나는이 같은 오류가되었고, 내 문제는 내가 포함 깜빡했다 :

props.put("mail.transport.protocol", "smtp");