mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-07 17:43:18 +02:00
Added option to use local IP address
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user