2016-06-28 75 views
0

を経由して失敗した私は、このコードを使用して、(メールプロバイダのweb.deを使用して)SMTP経由でメールを送信しています:SMTP - メールの送信は、プロキシ(JAVA)

package form.controll; 

import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 

public class NotificationControllerTest { 

    @Before 
    public void setUp() throws Exception { 
    } 

    @After 
    public void tearDown() throws Exception { 
    } 

    @Test 
    public void test() { 
    NotificationController aNotifi = new NotificationController("smtp.web.de", "587"); 
    aNotifi.sendEmail("[email protected]", "[email protected]", "THESENDERSPASSWORD", "New User Registration Notification", "New User has just been registered to blabla"); 
    } 

} 

これはうまく動作しますが、私が使用している場合

535認証資格無効

- なぜこれが起こるん:PROXYコンテキストで同じ方法で、 私は常にエラーを取得しますか? - メール送信の修正方法

答えて

1

あなたは読むべきthis FAQ answer

JavaMail does not currently support accessing mail servers through a web proxy server. One of the major reasons for using a proxy server is to allow HTTP requests from within a corporate network to pass through a corporate firewall. The firewall will typically block most access to the Internet, but will allow requests from the proxy server to pass through. In addition, a mail server inside the corporate network will perform a similar function for email, accepting messages via SMTP and forwarding them to their ultimate destination on the Internet, and accepting incoming messages and sending them to the appropriate internal mail server.

If your proxy server supports the SOCKS V4 or V5 protocol (http://www.socks.nec.com/aboutsocks.html , RFC1928) and allows anonymous connections, and you're using JDK 1.5 or newer and JavaMail 1.4.5 or newer, you can configure a SOCKS proxy on a per-session, per-protocol basis by setting the "mail.smtp.socks.host" property as described in the javadocs for the com.sun.mail.smtp package. Similar properties exist for the "imap" and "pop3" protocols.

If you're using older versions of the JDK or JavaMail, you can tell the Java runtime to direct all TCP socket connections to the SOCKS server. See the Networking Properties guide for the latest documentation of the socksProxyHost and socksProxyPort properties. These are system-level properties, not JavaMail session properties. They can be set from the command line when the application is invoked, for example: java -DsocksProxyHost=myproxy .... This facility can be used to direct the SMTP, IMAP, and POP3 communication from JavaMail to the SOCKS proxy server. Note that setting these properties directs all TCP sockets to the SOCKS proxy, which may have negative impact on other aspects of your application.

Without such a SOCKS server, if you want to use JavaMail to access mail servers outside the firewall indirectly, you might be able to use a program such as Corkscrew or connect to tunnel TCP connections through an HTTP proxy server. JavaMail does not support direct access through an HTTP proxy web server.

関連する問題