Added option to use local IP address

This commit is contained in:
M66B
2019-02-21 20:13:11 +01:00
parent 77e38e0a94
commit ba4e8df7ff
9 changed files with 1648 additions and 9 deletions

View File

@@ -55,6 +55,7 @@ import com.sun.mail.imap.IMAPStore;
import com.sun.mail.imap.protocol.FetchResponse;
import com.sun.mail.imap.protocol.IMAPProtocol;
import com.sun.mail.imap.protocol.UID;
import com.sun.mail.smtp.SMTPTransport;
import com.sun.mail.util.FolderClosedIOException;
import com.sun.mail.util.MailConnectException;
@@ -72,6 +73,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
@@ -1938,13 +1940,24 @@ public class ServiceSynchronize extends LifecycleService {
// Get properties
Properties props = MessageHelper.getSessionProperties(ident.auth_type, ident.realm, ident.insecure);
if (ident.starttls)
props.put("mail.smtp.localhost", ident.host);
else
props.put("mail.smtps.localhost", ident.host);
InetAddress ip = (ident.use_ip ? Helper.getLocalIp(ServiceSynchronize.this) : null);
if (ip == null) {
EntityLog.log(ServiceSynchronize.this, "Send local host=" + ident.host);
if (ident.starttls)
props.put("mail.smtp.localhost", ident.host);
else
props.put("mail.smtps.localhost", ident.host);
} else {
EntityLog.log(ServiceSynchronize.this, "Send local address=" + ip.getHostAddress());
if (ident.starttls)
props.put("mail.smtp.localaddress", ip.getHostAddress());
else
props.put("mail.smtps.localaddress", ip.getHostAddress());
}
// Create session
final Session isession = Session.getInstance(props, null);
isession.setDebug(true);
// Create message
MimeMessage imessage = MessageHelper.from(this, message, isession, ident.plain_only);