私はこのsmtpのことに非常に慣れていません..問題が発生しました..メールを送受信するサーバーメールとしてsmatermailを使用しています...クライアント側で、メールを送信するためのポートを変更できるテキストボックスを取得しました。 .ポート25を使用する場合は問題ありません..しかし、別のポートに変更すると、smatermail eq 8025のポートでさえメールを送信したくありません..サーバーのように実行されますが、25以外のポートをリッスンしません..
ログにエラーが表示されます
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: 192.168.56.30, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:345)
at javax.mail.Service.connect(Service.java:226)
at javax.mail.Service.connect(Service.java:175)
at javax.mail.Transport.send0(Transport.java:253)
at javax.mail.Transport.send(Transport.java:124)
at com.mastersam.analyst.compass.engine.mail.Mailer$SenderWorker.run(Mailer.java:150)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:297)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:229)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
... 7 more
これはクライアント側のコードです
package com.mastersam.analyst.compass.engine.mail;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Properties;
import javax.mail.Address;
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;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.mastersam.analyst.compass.model.ApplicationSettingModel;
/**
* Sends email updates. Multiple recipient must be semicolon-separated.
*/
public class Mailer {
private static Log log = LogFactory.getLog(Mailer.class);
private static Mailer self = new Mailer();
public static Mailer instance() {
return self;
}
/**
* Sends email alerts to recepient(s).
*
* @param to
* (Semicolon-separated if multiple) recipients address
* @param subject
* @param content
* Must be in textual form.
*/
public void send(String[] to, String subject, String content)
throws MessagingException, UnsupportedEncodingException {
ApplicationSettingModel setting = ApplicationSettingModel.ThreadLocalSetting
.get();
if (setting == null) {
throw new RuntimeException(
"ApplicationSetting is not bind to current thread.");
}
SenderWorker worker = new SenderWorker(setting, to, subject, content);
worker.start();
}
/**
* Extract name form email address. E.g simon@example.com will return simon.
*/
private static String getPersonalName(String add) {
int ind = add.indexOf("@");
return add.substring(0, ind);
}
/**
* Init SMTP Authenticator
*/
private static class SMTPAuthenticator extends Authenticator {
PasswordAuthentication auth;
public SMTPAuthenticator(String username, String password) {
auth = new PasswordAuthentication(username, password);
}
protected PasswordAuthentication getPasswordAuthentication() {
return auth;
}
}
/**
* Mailer internal class to configure and send SMTP mail
*/
private static class SenderWorker extends Thread {
private ApplicationSettingModel setting;
private String[] to;
private String subject;
private String content;
public SenderWorker(ApplicationSettingModel setting, String[] to,
String subject, String content) {
this.setting = setting;
this.to = to;
this.subject = subject;
this.content = content;
}
/**
* configure and return mail message
*
* @param session
* javax.mail.Session
* @return return configured mail message
* @throws UnsupportedEncodingException
* @throws MessagingException
*/
private Message getMessage(Session session)
throws UnsupportedEncodingException, MessagingException {
Address[] toRecp = new Address[to.length];
for (int i = 0; i < toRecp.length; i++) {
toRecp[i] = new InternetAddress(to[i], getPersonalName(to[i]));
}
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(setting.getSmtpMail(),
getPersonalName(setting.getSmtpMail())));
msg.setRecipients(Message.RecipientType.TO, toRecp);
msg.setSubject(subject);
msg.setText(content);
Date d = new Date();
msg.setSentDate(d);
return msg;
}
public void run() {
Properties authProps = new Properties();
Properties normProps = new Properties();
Session session = null;
boolean requireAuth = setting.getSmtpMode().trim()
.equalsIgnoreCase("Authenticated");
boolean sent = false;
authProps.put("mail.smtp.host", setting.getSmtp());
normProps.put("mail.smtp.host", setting.getSmtp());
if (requireAuth) {
authProps.put("mail.smtp.auth", "true");
session = Session.getInstance(authProps, new SMTPAuthenticator(
setting.getSmtpUser(), setting.getSmtpPass()));
try {
Transport.send(getMessage(session));
sent = true;
} catch (Exception e) {
log.error("run", e);
}
}
if (!sent) {
session = Session.getInstance(normProps, null);
try {
Transport.send(getMessage(session));
} catch (Exception e) {
log.error("run", e);
}
}
}
}
}
..ポートをデフォルトにするコードがどこにあるかを見つけようとしています..誰かがこの問題とコードで行う必要がある変更について私を助けてくれますか..ありがとう、私の英語で申し訳ありません..私はまだ学んでいますそれ..