誰かがcPanelの電子メールa/csに接続して電子メールを送信するJava電子メール/smtp/imapクライアントプログラムを試した/見つけた場合は、それを共有してください. そのコードをオンラインで見つけようとするのは骨の折れる作業でしたが、どれもうまく動作しません。5 種類以上のコードを試しましたが、うまくいきませんでした。以下にいくつかのサンプルを示します。
サンプル#1
String host = "mail.domain.net";
String user = "catch-all@domain.net";
String pass = "xxxx";
String to = "admin@domain.net";
String from = "catch-all@domain.net";
String subject = "Dummy subject";
String messageText = "Dummy body";
boolean sessionDebug = false;
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", 2525); //25 - default
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
try {
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, pass);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
} catch (Exception e) {
e.printStackTrace();
}
エラー
Sending mail.. Done!javax.mail.MessagingException: Could not connect to SMTP host: mail.dealstock.net, port: 25;
nested exception is:
java.net.ConnectException: Connection refused
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1706)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:192)
at com.mail.EmailsSender2.main(EmailsSender2.java:209)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:284)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)
at com.sun.mai
Cpanel アカウントから、指定されたポートは 2525 で、保護されている場合は 465 ですが、どのポートも機能しません。ポスト 2525 では、接続しますが、応答がなく、1 ~ 2 分待ってからタイムアウトします。ポート 25 に変更すると、単純に上記のエラーがスローされます。同じ Cpanel メール a/c を使用すると、別のプログラムで POP を介してメールに接続して読み取ることができますが、メールの送信に失敗します。
コメント/入力を共有していただければ幸いです。