Search in sources :

Example 16 with EMail

use of org.compiere.util.EMail 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)

Example 17 with EMail

use of org.compiere.util.EMail in project adempiere by adempiere.

the class WEMailDialog method onEvent.

//	getAttachment
/**************************************************************************
	 * 	Action Listener - Send email
	 */
public void onEvent(Event event) throws Exception {
    if (event.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
        onClose();
    if (getTo() == null || getTo().length() == 0) {
        return;
    }
    //	Send
    if (event.getTarget().getId().equals(ConfirmPanel.A_OK)) {
        StringTokenizer st = new StringTokenizer(getTo(), " ,;", false);
        String to = st.nextToken();
        EMail email = m_client.createEMail(getFrom(), to, getSubject(), getMessage());
        String status = "Check Setup";
        if (email != null) {
            while (st.hasMoreTokens()) email.addTo(st.nextToken());
            // cc
            StringTokenizer stcc = new StringTokenizer(getCc(), " ,;", false);
            while (stcc.hasMoreTokens()) {
                String cc = stcc.nextToken();
                if (cc != null && cc.length() > 0)
                    email.addCc(cc);
            }
            //	Attachment
            if (m_attachFile != null && m_attachFile.exists())
                email.addAttachment(m_attachFile);
            status = email.send();
            //
            if (m_user != null)
                new MUserMail(m_user, m_user.getAD_User_ID(), email).saveEx();
            if (email.isSentOK()) {
                FDialog.info(0, this, "MessageSent");
                onClose();
            } else
                FDialog.error(0, this, "MessageNotSent", status);
        } else
            FDialog.error(0, this, "MessageNotSent", status);
    //
    //			confirmPanel.getOKButton().setEnabled(false);
    //			setCursor(Cursor.getDefaultCursor());
    } else if (event.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
        onClose();
}
Also used : StringTokenizer(java.util.StringTokenizer) MUserMail(org.compiere.model.MUserMail) EMail(org.compiere.util.EMail)

Aggregations

EMail (org.compiere.util.EMail)17 MUserMail (org.compiere.model.MUserMail)8 MUser (org.compiere.model.MUser)5 MMailText (org.compiere.model.MMailText)4 File (java.io.File)3 MClient (org.compiere.model.MClient)3 ReportEngine (org.compiere.print.ReportEngine)3 SQLException (java.sql.SQLException)2 Timestamp (java.sql.Timestamp)2 StringTokenizer (java.util.StringTokenizer)2 MAsset (org.compiere.model.MAsset)2 MBPartner (org.compiere.model.MBPartner)2 MQuery (org.compiere.model.MQuery)2 PrintInfo (org.compiere.model.PrintInfo)2 MPrintFormat (org.compiere.print.MPrintFormat)2 AdempiereUserError (org.compiere.util.AdempiereUserError)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 PreparedStatement (java.sql.PreparedStatement)1