Search in sources :

Example 1 with MMailMsg

use of org.compiere.model.MMailMsg in project adempiere by adempiere.

the class WebUtil method sendEMail.

//	deleteCookieWebUser
/**************************************************************************
	 * 	Send EMail
	 *	@param request request
	 *	@param to web user
	 *	@param msgType see MMailMsg.MAILMSGTYPE_*
	 *	@param parameter object array with parameters
	 * 	@return mail EMail.SENT_OK or error message 
	 */
public static String sendEMail(HttpServletRequest request, WebUser to, String msgType, Object[] parameter) {
    WebSessionCtx wsc = WebSessionCtx.get(request);
    MStore wStore = wsc.wstore;
    MMailMsg mailMsg = wStore.getMailMsg(msgType);
    //
    StringBuffer subject = new StringBuffer(mailMsg.getSubject());
    if (parameter.length > 0 && parameter[0] != null)
        subject.append(parameter[0]);
    //
    StringBuffer message = new StringBuffer();
    String hdr = wStore.getEMailFooter();
    if (hdr != null && hdr.length() > 0)
        message.append(hdr).append("\n");
    message.append(mailMsg.getMessage());
    if (parameter.length > 1 && parameter[1] != null)
        message.append(parameter[1]);
    if (mailMsg.getMessage2() != null) {
        message.append("\n").append(mailMsg.getMessage2());
        if (parameter.length > 2 && parameter[2] != null)
            message.append(parameter[2]);
    }
    if (mailMsg.getMessage3() != null) {
        message.append("\n").append(mailMsg.getMessage3());
        if (parameter.length > 3 && parameter[3] != null)
            message.append(parameter[3]);
    }
    message.append(MRequest.SEPARATOR).append("http://").append(request.getServerName()).append(request.getContextPath()).append("/ - ").append(wStore.getName()).append("\n").append("Request from: ").append(getFrom(request)).append("\n");
    String ftr = wStore.getEMailFooter();
    if (ftr != null && ftr.length() > 0)
        message.append(ftr);
    //	Create Mail
    EMail email = wStore.createEMail(to.getEmail(), subject.toString(), message.toString());
    //	CC Order
    if (msgType.equals(MMailMsg.MAILMSGTYPE_OrderAcknowledgement)) {
        String orderEMail = wStore.getWebOrderEMail();
        String storeEMail = wStore.getWStoreEMail();
        if (orderEMail != null && orderEMail.length() > 0 && //	already Bcc
        !orderEMail.equals(storeEMail))
            email.addBcc(orderEMail);
    }
    //	Send
    String retValue = email.send();
    //	Log
    MUserMail um = new MUserMail(mailMsg, to.getAD_User_ID(), email);
    um.saveEx();
    //
    return retValue;
}
Also used : MUserMail(org.compiere.model.MUserMail) MMailMsg(org.compiere.model.MMailMsg) MStore(org.compiere.model.MStore)

Example 2 with MMailMsg

use of org.compiere.model.MMailMsg in project adempiere by adempiere.

the class MobileUtil method sendEMail.

//	deleteCookieWebUser
/**************************************************************************
	 * 	Send EMail
	 *	@param request request
	 *	@param to web user
	 *	@param msgType see MMailMsg.MAILMSGTYPE_*
	 *	@param parameter object array with parameters
	 * 	@return mail EMail.SENT_OK or error message 
	 */
public static String sendEMail(HttpServletRequest request, WebUser to, String msgType, Object[] parameter) {
    MobileSessionCtx wsc = MobileSessionCtx.get(request);
    MStore wStore = wsc.wstore;
    MMailMsg mailMsg = wStore.getMailMsg(msgType);
    //
    StringBuffer subject = new StringBuffer(mailMsg.getSubject());
    if (parameter.length > 0 && parameter[0] != null)
        subject.append(parameter[0]);
    //
    StringBuffer message = new StringBuffer();
    String hdr = wStore.getEMailFooter();
    if (hdr != null && hdr.length() > 0)
        message.append(hdr).append("\n");
    message.append(mailMsg.getMessage());
    if (parameter.length > 1 && parameter[1] != null)
        message.append(parameter[1]);
    if (mailMsg.getMessage2() != null) {
        message.append("\n").append(mailMsg.getMessage2());
        if (parameter.length > 2 && parameter[2] != null)
            message.append(parameter[2]);
    }
    if (mailMsg.getMessage3() != null) {
        message.append("\n").append(mailMsg.getMessage3());
        if (parameter.length > 3 && parameter[3] != null)
            message.append(parameter[3]);
    }
    message.append(MRequest.SEPARATOR).append("http://").append(request.getServerName()).append(request.getContextPath()).append("/ - ").append(wStore.getName()).append("\n").append("Request from: ").append(getFrom(request)).append("\n");
    String ftr = wStore.getEMailFooter();
    if (ftr != null && ftr.length() > 0)
        message.append(ftr);
    //	Create Mail
    EMail email = wStore.createEMail(to.getEmail(), subject.toString(), message.toString());
    //	CC Order
    if (msgType.equals(MMailMsg.MAILMSGTYPE_OrderAcknowledgement)) {
        String orderEMail = wStore.getWebOrderEMail();
        String storeEMail = wStore.getWStoreEMail();
        if (orderEMail != null && orderEMail.length() > 0 && //	already Bcc
        !orderEMail.equals(storeEMail))
            email.addBcc(orderEMail);
    }
    //	Send
    String retValue = email.send();
    //	Log
    MUserMail um = new MUserMail(mailMsg, to.getAD_User_ID(), email);
    um.saveEx();
    //
    return retValue;
}
Also used : MUserMail(org.compiere.model.MUserMail) MMailMsg(org.compiere.model.MMailMsg) MStore(org.compiere.model.MStore) EMail(org.compiere.util.EMail)

Aggregations

MMailMsg (org.compiere.model.MMailMsg)2 MStore (org.compiere.model.MStore)2 MUserMail (org.compiere.model.MUserMail)2 EMail (org.compiere.util.EMail)1