5

GMail を使用するために Websphere 7 で Javamail セッションを作成しようとしていますが、認証は常に失敗します。

はい、私のパスワードは大丈夫です...

セッションを次のように構成しています。

出力メールのプロパティ

  • プロバイダー: 組み込みのメール プロバイダー
  • JNDI: メール/セッション/デフォルト
  • デバッグ: オン
  • サーバー: smtp.gmail.com
  • プロトコル: smtp
  • ユーザー: myuser@gmail.com
  • パスワード: mypassword
  • パスワードの確認: 上記と同じ
  • 返信メール: myuser@gmail.com

セッションのプロパティには、次のものがあります。

  • mail.smtp.auth = true
  • メール.smtp.ポート = 465
  • mail.smtp.starttls.enable = true
  • mail.smtp.socketFactory.port = 465
  • mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory

私はテストJSPを次のようなもので使用しています...

...
System.out.println("Entering MailJsp!");

String errorMessage = null;
String destinationAddress = request.getParameter("destinationAddress");
String messageBody = request.getParameter("message");
String subject = "Mail from MailServlet";
String emailFrom = "myuser@gmail.com"; 

// try only if it is not the first request
if (destinationAddress != null) {

    System.out.println("Sending email");
    try 
    {
        // look up MailSession
        Context context = new InitialContext();
        Session mailSession =  (Session)context.lookup("mail/session/Default");

        System.out.println("Mail Session Properties: " + mailSession.getProperties());
        Message msg = new MimeMessage(mailSession);
        msg.setFrom(new InternetAddress(emailFrom));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(destinationAddress));

        // Set the subject and body text
        msg.setSubject(subject);
        msg.setText(messageBody);

        // send message
        Transport.send(msg);
        System.out.println("Email Sent");
    }
    catch (Exception e) 
    {
        System.out.println("Error sending Email: " + e);
        e.printStackTrace();
        errorMessage = e.getMessage() != null ? e.getMessage() : e.toString();
    }
}
System.out.println("Exiting MailJsp");

...

...そして、私の結果ログは次のとおりです。

Entering MailJsp!
Sending email
DEBUG: JavaMail version 1.4ea
DEBUG: java.io.FileNotFoundException: C:\environment\server\IBM\WAS7\AppServer\java\jre\lib\javamail.providers (The system cannot find the file specified.)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\environment\server\IBM\WAS7\AppServer\java\jre\lib\javamail.address.map (The system cannot find the file specified.)
*** In SessionFactory.setPasswordAuthentication, TRANSPORT PasswordAuthentication is based on:
    url=smtp://myuser@gmail.com@smtp.gmail.com:465
    user=myuser@gmail.com
    password=********
*** In SessionFactory.getObjectInstance, session properties:
    mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
    mail.transport.protocol=smtp
    mail.imaps.class=com.sun.mail.imap.IMAPSSLStore
    mail.smtp.host=smtp.gmail.com
    mail.debug=true
    mail.from=myuser@gmail.com
    mail.pop3s.class=com.sun.mail.pop3.POP3SSLStore
    mail.smtp.starttls.enable=true
    mail.smtp.port=465
    mail.smtp.class=com.sun.mail.smtp.SMTPTransport
    mail.smtp.auth=true
    mail.smtps.class=com.sun.mail.smtp.SMTPSSLTransport
    mail.smtp.socketFactory.port=465
    mail.smtp.user=myuser@gmail.com
    mail.imap.class=com.sun.mail.imap.IMAPStore
    mail.mime.address.strict=true
    mail.pop3.class=com.sun.mail.pop3.POP3Store
Mail Session Properties: {mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory, mail.transport.protocol=smtp, mail.imaps.class=com.sun.mail.imap.IMAPSSLStore, mail.smtp.host=smtp.gmail.com, mail.debug=true, mail.from=myuser@gmail.com, mail.pop3s.class=com.sun.mail.pop3.POP3SSLStore, mail.smtp.starttls.enable=true, mail.smtp.port=465, mail.smtp.class=com.sun.mail.smtp.SMTPTransport, mail.smtp.auth=true, mail.smtps.class=com.sun.mail.smtp.SMTPSSLTransport, mail.smtp.socketFactory.port=465, mail.smtp.user=myuser@gmail.com, mail.imap.class=com.sun.mail.imap.IMAPStore, mail.mime.address.strict=true, mail.pop3.class=com.sun.mail.pop3.POP3Store}
DEBUG: mail.smtp.class property exists and points to com.sun.mail.smtp.SMTPTransport
DEBUG SMTP: useEhlo true, useAuth true
Error sending Email: javax.mail.AuthenticationFailedException
javax.mail.AuthenticationFailedException
    at javax.mail.Service.connect(Service.java:306)
    at javax.mail.Service.connect(Service.java:156)
    at javax.mail.Service.connect(Service.java:105)
    at javax.mail.Transport.send0(Transport.java:168)
    at javax.mail.Transport.send(Transport.java:98)
    at com.ibm._jsp._email._jspService(_email.java:127)
    at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:98)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1443)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1384)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:104)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:852)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:785)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:443)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:175)
    at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:121)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:234)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3610)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:274)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:926)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1557)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:173)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:272)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:202)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:766)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:896)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)
Exiting MailJsp

別の方法で使用すると、うまくいきます!

Session mailSession =  (Session)context.lookup("mail/session/Default");
Properties props = mailSession.getProperties();

mailSession = Session.getDefaultInstance(
    props,
    new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("myuser@gmail.com","mypassword");
        }
    });

しかし、管理コンソールで設定されたパスワードを使用し、プログラムで提供したくありません。したがって、ユーザーは自分のパスワードを管理できます。

誰か助けてくれませんか?

tks

4

2 に答える 2

0

統合ソリューション コンソール

Mail Sessions > WPexchange > Custom properties > mail.smtp.port

Name: mail.smtp.port
Value: 587
于 2013-10-03T08:47:22.663 に答える