IDEMPIERE-722 Make email credentials configuration more flexible

This commit is contained in:
Carlos Ruiz 2013-04-23 15:16:38 -05:00
parent cbd06adec1
commit 652d86479d
6 changed files with 144 additions and 31 deletions

View File

@ -0,0 +1,7 @@
-- Mar 11, 2013 5:56:17 PM COT
INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Value,Description,AD_SysConfig_UU,Created,Updated,AD_Client_ID,AD_Org_ID,CreatedBy,IsActive,UpdatedBy,Name) VALUES (200027,'D','C','U','From where to get the outgoing credentials for email (U : User / C : Client / S : System)','8a4f70c3-b361-431a-9357-809b9f01abc4',TO_DATE('2013-03-11 17:56:16','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2013-03-11 17:56:16','YYYY-MM-DD HH24:MI:SS'),0,0,100,'Y',100,'MAIL_SEND_CREDENTIALS')
;
SELECT register_migration_script('201304231000_IDEMPIERE-722.sql') FROM dual
;

View File

@ -0,0 +1,7 @@
-- Mar 11, 2013 5:56:17 PM COT
INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Value,Description,AD_SysConfig_UU,Created,Updated,AD_Client_ID,AD_Org_ID,CreatedBy,IsActive,UpdatedBy,Name) VALUES (200027,'D','C','U','From where to get the outgoing credentials for email (U : User / C : Client / S : System)','8a4f70c3-b361-431a-9357-809b9f01abc4',TO_DATE('2013-03-11 17:56:16','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2013-03-11 17:56:16','YYYY-MM-DD HH24:MI:SS'),0,0,100,'Y',100,'MAIL_SEND_CREDENTIALS')
;
SELECT register_migration_script('201304231000_IDEMPIERE-722.sql') FROM dual
;

View File

@ -17,6 +17,9 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import static org.compiere.model.MSysConfig.CLIENT_ACCOUNTING;
import static org.compiere.model.MSysConfig.MAIL_SEND_CREDENTIALS;
import java.io.File; import java.io.File;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -56,7 +59,7 @@ public class MClient extends X_AD_Client
/** /**
* *
*/ */
private static final long serialVersionUID = -1242880454287104705L; private static final long serialVersionUID = 3043792947325698506L;
/** /**
* Get client * Get client
@ -182,18 +185,6 @@ public class MClient extends X_AD_Client
/** Client Info Setup Tree for Account */ /** Client Info Setup Tree for Account */
private int m_AD_Tree_Account_ID; private int m_AD_Tree_Account_ID;
/**
* Get SMTP Host
* @return SMTP or loaclhost
*/
public String getSMTPHost()
{
String s = super.getSMTPHost();
if (s == null)
s = "localhost";
return s;
} // getSMTPHost
/** /**
* Get Client Info * Get Client Info
* @return Client Info * @return Client Info
@ -459,9 +450,9 @@ public class MClient extends X_AD_Client
return msgreturn.toString(); return msgreturn.toString();
} }
// //
StringBuilder msgce = new StringBuilder("Adempiere EMail Test: ").append(toString()); StringBuilder msgce = new StringBuilder("iDempiere EMail Test: ").append(toString());
EMail email = createEMail (getRequestEMail(), EMail email = createEMail (getRequestEMail(),
"Adempiere EMail Test",msgce.toString()); "iDempiere EMail Test",msgce.toString());
if (email == null){ if (email == null){
StringBuilder msgreturn = new StringBuilder("Could not create EMail: ").append(getName()); StringBuilder msgreturn = new StringBuilder("Could not create EMail: ").append(getName());
return msgreturn.toString(); return msgreturn.toString();
@ -852,7 +843,7 @@ public class MClient extends X_AD_Client
{ {
log.warning("From EMail incomplete: " + from + " (" + getName() + ")"); log.warning("From EMail incomplete: " + from + " (" + getName() + ")");
return null; return null;
} }
// //
EMail email = new EMail (this, EMail email = new EMail (this,
from.getEMail(), from.getEMail(),
@ -861,6 +852,9 @@ public class MClient extends X_AD_Client
message, html); message, html);
if (isSmtpAuthorization()) if (isSmtpAuthorization())
email.createAuthenticator (from.getEMailUser(), from.getEMailUserPW()); email.createAuthenticator (from.getEMailUser(), from.getEMailUserPW());
if (from.getEMail() != null && ! from.getEMail().equalsIgnoreCase(from.getEMailUser())) {
email.setReplyTo(from.getEMail());
}
return email; return email;
} // createEMail } // createEMail
@ -878,21 +872,21 @@ public class MClient extends X_AD_Client
private static final String CLIENT_ACCOUNTING_IMMEDIATE = "I"; private static final String CLIENT_ACCOUNTING_IMMEDIATE = "I";
public static boolean isClientAccounting() { public static boolean isClientAccounting() {
String ca = MSysConfig.getValue(MSysConfig.CLIENT_ACCOUNTING, String ca = MSysConfig.getValue(CLIENT_ACCOUNTING,
CLIENT_ACCOUNTING_QUEUE, // default CLIENT_ACCOUNTING_QUEUE, // default
Env.getAD_Client_ID(Env.getCtx())); Env.getAD_Client_ID(Env.getCtx()));
return (ca.equalsIgnoreCase(CLIENT_ACCOUNTING_IMMEDIATE) || ca.equalsIgnoreCase(CLIENT_ACCOUNTING_QUEUE)); return (ca.equalsIgnoreCase(CLIENT_ACCOUNTING_IMMEDIATE) || ca.equalsIgnoreCase(CLIENT_ACCOUNTING_QUEUE));
} }
public static boolean isClientAccountingQueue() { public static boolean isClientAccountingQueue() {
String ca = MSysConfig.getValue(MSysConfig.CLIENT_ACCOUNTING, String ca = MSysConfig.getValue(CLIENT_ACCOUNTING,
CLIENT_ACCOUNTING_QUEUE, // default CLIENT_ACCOUNTING_QUEUE, // default
Env.getAD_Client_ID(Env.getCtx())); Env.getAD_Client_ID(Env.getCtx()));
return ca.equalsIgnoreCase(CLIENT_ACCOUNTING_QUEUE); return ca.equalsIgnoreCase(CLIENT_ACCOUNTING_QUEUE);
} }
public static boolean isClientAccountingImmediate() { public static boolean isClientAccountingImmediate() {
String ca = MSysConfig.getValue(MSysConfig.CLIENT_ACCOUNTING, String ca = MSysConfig.getValue(CLIENT_ACCOUNTING,
CLIENT_ACCOUNTING_QUEUE, // default CLIENT_ACCOUNTING_QUEUE, // default
Env.getAD_Client_ID(Env.getCtx())); Env.getAD_Client_ID(Env.getCtx()));
return ca.equalsIgnoreCase(CLIENT_ACCOUNTING_IMMEDIATE); return ca.equalsIgnoreCase(CLIENT_ACCOUNTING_IMMEDIATE);
@ -968,17 +962,91 @@ public class MClient extends X_AD_Client
return (Collections.binarySearch(m_fieldAccess, aDFieldID) > 0); return (Collections.binarySearch(m_fieldAccess, aDFieldID) > 0);
} }
@Override @Override
protected boolean beforeSave(boolean newRecord) public String getRequestUser() {
{ // IDEMPIERE-722
//gmail specific support if (getAD_Client_ID() != 0 && isSendCredentialsSystem()) {
if ("smtp.gmail.com".equals(getSMTPHost())) MClient sysclient = MClient.get(getCtx(), 0);
{ return sysclient.getRequestUser();
if (getSMTPPort() == 0)
setSMTPPort(587);
} }
return true; return super.getRequestUser();
}
@Override
public String getRequestUserPW() {
// IDEMPIERE-722
if (getAD_Client_ID() != 0 && isSendCredentialsSystem()) {
MClient sysclient = MClient.get(getCtx(), 0);
return sysclient.getRequestUserPW();
}
return super.getRequestUserPW();
}
@Override
public boolean isSmtpAuthorization() {
// IDEMPIERE-722
if (getAD_Client_ID() != 0 && isSendCredentialsSystem()) {
MClient sysclient = MClient.get(getCtx(), 0);
return sysclient.isSmtpAuthorization();
}
return super.isSmtpAuthorization();
}
@Override
public int getSMTPPort() {
// IDEMPIERE-722
if (getAD_Client_ID() != 0 && isSendCredentialsSystem()) {
MClient sysclient = MClient.get(getCtx(), 0);
return sysclient.getSMTPPort();
}
return super.getSMTPPort();
}
@Override
public boolean isSecureSMTP() {
// IDEMPIERE-722
if (getAD_Client_ID() != 0 && isSendCredentialsSystem()) {
MClient sysclient = MClient.get(getCtx(), 0);
return sysclient.isSecureSMTP();
}
return super.isSecureSMTP();
}
/**
* Get SMTP Host
* @return SMTP or loaclhost
*/
@Override
public String getSMTPHost() {
String s = null;
if (getAD_Client_ID() != 0 && isSendCredentialsSystem()) {
MClient sysclient = MClient.get(getCtx(), 0);
s = sysclient.getSMTPHost();
} else {
s = super.getSMTPHost();
}
if (s == null)
s = "localhost";
return s;
} // getSMTPHost
// IDEMPIERE-722
private static final String MAIL_SEND_CREDENTIALS_USER = "U";
private static final String MAIL_SEND_CREDENTIALS_CLIENT = "C";
private static final String MAIL_SEND_CREDENTIALS_SYSTEM = "S";
public static boolean isSendCredentialsClient() {
String msc = MSysConfig.getValue(MAIL_SEND_CREDENTIALS,
MAIL_SEND_CREDENTIALS_USER, // default
Env.getAD_Client_ID(Env.getCtx()));
return (MAIL_SEND_CREDENTIALS_CLIENT.equalsIgnoreCase(msc));
}
public static boolean isSendCredentialsSystem() {
String msc = MSysConfig.getValue(MAIL_SEND_CREDENTIALS,
MAIL_SEND_CREDENTIALS_USER, // default
Env.getAD_Client_ID(Env.getCtx()));
return (MAIL_SEND_CREDENTIALS_SYSTEM.equalsIgnoreCase(msc));
} }
} // MClient } // MClient

View File

@ -42,7 +42,8 @@ public class MSysConfig extends X_AD_SysConfig
/** /**
* *
*/ */
private static final long serialVersionUID = 6995907727239458114L; private static final long serialVersionUID = -872111480299074889L;
public final static String PDF_FONT_DIR = "PDF_FONT_DIR"; public final static String PDF_FONT_DIR = "PDF_FONT_DIR";
public final static String TWOPACK_HANDLE_TRANSLATIONS = "2PACK_HANDLE_TRANSLATIONS"; public final static String TWOPACK_HANDLE_TRANSLATIONS = "2PACK_HANDLE_TRANSLATIONS";
public static final String ZK_DESKTOP_CLASS = "ZK_DESKTOP_CLASS"; public static final String ZK_DESKTOP_CLASS = "ZK_DESKTOP_CLASS";
@ -109,6 +110,7 @@ public class MSysConfig extends X_AD_SysConfig
public static final String SWING_OVERRIDE_TEXT_AREA_BEHAVIOUR = "SWING_OVERRIDE_TEXT_AREA_BEHAVIOUR"; public static final String SWING_OVERRIDE_TEXT_AREA_BEHAVIOUR = "SWING_OVERRIDE_TEXT_AREA_BEHAVIOUR";
public static final String MAIL_SEND_BCC_TO_ADDRESS = "MAIL_SEND_BCC_TO_ADDRESS"; public static final String MAIL_SEND_BCC_TO_ADDRESS = "MAIL_SEND_BCC_TO_ADDRESS";
public static final String MAIL_SEND_BCC_TO_FROM = "MAIL_SEND_BCC_TO_FROM"; public static final String MAIL_SEND_BCC_TO_FROM = "MAIL_SEND_BCC_TO_FROM";
public static final String MAIL_SEND_CREDENTIALS = "MAIL_SEND_CREDENTIALS";
public static final String REAL_TIME_POS = "REAL_TIME_POS"; public static final String REAL_TIME_POS = "REAL_TIME_POS";
public static final String SHIPPING_DEFAULT_WEIGHT_PER_PACKAGE = "SHIPPING_DEFAULT_WEIGHT_PER_PACKAGE"; public static final String SHIPPING_DEFAULT_WEIGHT_PER_PACKAGE = "SHIPPING_DEFAULT_WEIGHT_PER_PACKAGE";
public static final String SHIPPING_SAVE_REQUEST_RESPONSE_LOG = "SHIPPING_SAVE_REQUEST_RESPONSE_LOG"; public static final String SHIPPING_SAVE_REQUEST_RESPONSE_LOG = "SHIPPING_SAVE_REQUEST_RESPONSE_LOG";

View File

@ -56,7 +56,7 @@ public class MUser extends X_AD_User
/** /**
* *
*/ */
private static final long serialVersionUID = 239972951892250043L; private static final long serialVersionUID = -1916348077418252152L;
/** /**
* Get active Users of BPartner * Get active Users of BPartner
@ -1026,4 +1026,33 @@ public class MUser extends X_AD_User
// org.compiere.Adempiere.startupClient(); // org.compiere.Adempiere.startupClient();
// System.out.println ( MUser.get(Env.getCtx(), "SuperUser", "22") ); // System.out.println ( MUser.get(Env.getCtx(), "SuperUser", "22") );
} // main /* */ } // main /* */
@Override
public String getEMailUser() {
// IDEMPIERE-722
if (MClient.isSendCredentialsSystem()) {
MClient sysclient = MClient.get(getCtx(), 0);
return sysclient.getRequestUser();
} else if (MClient.isSendCredentialsClient()) {
MClient client = MClient.get(getCtx());
return client.getRequestUser();
} else {
return super.getEMailUser();
}
}
@Override
public String getEMailUserPW() {
// IDEMPIERE-722
if (MClient.isSendCredentialsSystem()) {
MClient sysclient = MClient.get(getCtx(), 0);
return sysclient.getRequestUserPW();
} else if (MClient.isSendCredentialsClient()) {
MClient client = MClient.get(getCtx());
return client.getRequestUserPW();
} else {
return super.getEMailUserPW();
}
}
} // MUser } // MUser

View File

@ -305,7 +305,7 @@ public final class EMail implements Serializable
m_msg.setReplyTo(new Address[] {m_replyTo}); m_msg.setReplyTo(new Address[] {m_replyTo});
// //
m_msg.setSentDate(new java.util.Date()); m_msg.setSentDate(new java.util.Date());
m_msg.setHeader("Comments", "AdempiereMail"); m_msg.setHeader("Comments", "iDempiereMail");
// m_msg.setDescription("Description"); // m_msg.setDescription("Description");
// SMTP specifics // SMTP specifics
m_msg.setAllow8bitMIME(true); m_msg.setAllow8bitMIME(true);