Search in sources :

Example 11 with EMail

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

the class MClient method sendEMailAttachments.

/**
	 * 	Send EMail from Request User - with trace
	 *	@param AD_User_ID recipient
	 *	@param subject subject
	 *	@param message message
	 *	@param attachment optional collection of attachments
	 *  @param html
	 *	@return true if sent
	 */
public boolean sendEMailAttachments(int AD_User_ID, String subject, String message, Collection<File> attachments, boolean html) {
    MUser to = MUser.get(getCtx(), AD_User_ID);
    String toEMail = to.getEMail();
    if (toEMail == null || toEMail.length() == 0) {
        log.warning("No EMail for recipient: " + to);
        return false;
    }
    EMail email = createEMail(null, to, subject, message, html);
    if (email == null)
        return false;
    email.addAttachments(attachments);
    try {
        return sendEmailNow(null, to, email);
    } catch (Exception ex) {
        log.severe(getName() + " - " + ex.getLocalizedMessage());
        return false;
    }
}
Also used : EMail(org.compiere.util.EMail) SQLException(java.sql.SQLException)

Example 12 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 13 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)

Example 14 with EMail

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

the class MStore method sendEMail.

//	createEMail
/**
	 * 	Send EMail from WebStore User
	 *	@param to recipient email address
	 *	@param subject subject
	 *	@param message message - add header & footer 
	 *	@return true if sent
	 */
public boolean sendEMail(String to, String subject, String message) {
    if (message == null || message.length() == 0) {
        log.warning("No Message");
        return false;
    }
    StringBuffer msgText = new StringBuffer();
    if (getEMailHeader() != null)
        msgText.append(getEMailHeader());
    msgText.append(message);
    if (getEMailFooter() != null)
        msgText.append(getEMailFooter());
    //
    EMail email = createEMail(to, subject, msgText.toString());
    if (email == null)
        return false;
    try {
        String msg = email.send();
        if (EMail.SENT_OK.equals(email.send())) {
            log.info("Sent EMail " + subject + " to " + to);
            return true;
        } else {
            log.warning("Could NOT Send Email: " + subject + " to " + to + ": " + msg + " (" + getName() + ")");
            return false;
        }
    } catch (Exception ex) {
        log.severe(getName() + " - " + ex.getLocalizedMessage());
        return false;
    }
}
Also used : EMail(org.compiere.util.EMail)

Example 15 with EMail

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

the class MStore method createEMail.

//	beforeSave
/************
	 * 	Create EMail from Request User
	 *	@param to recipient
	 *	@param subject sunject
	 *	@param message nessage
	 *	@return EMail
	 */
public EMail createEMail(String to, String subject, String message) {
    if (to == null || to.length() == 0) {
        log.warning("No To");
        return null;
    }
    //
    EMail email = null;
    MClient client = MClient.get(getCtx(), getAD_Client_ID());
    if (client.isServerEMail() && Ini.isClient()) {
        Server server = CConnection.get().getServer();
        try {
            if (server != null) {
                //	See ServerBean
                email = server.createEMail(Env.getRemoteCallCtx(getCtx()), getAD_Client_ID(), to, subject, message);
            } else
                log.log(Level.WARNING, "No AppsServer");
        } catch (Exception ex) {
            log.log(Level.SEVERE, getName() + " - AppsServer error", ex);
        }
    }
    String from = getWStoreEMail();
    if (from == null || from.length() == 0)
        from = client.getRequestEMail();
    if (email == null)
        email = new EMail(client, from, to, subject, message);
    //	Authorizetion
    if (client.isSmtpAuthorization()) {
        if (getWStoreEMail() != null && getWStoreUser() != null && getWStoreUserPW() != null)
            email.createAuthenticator(getWStoreUser(), getWStoreUserPW());
        else
            email.createAuthenticator(client.getRequestUser(), client.getRequestUserPW());
    }
    //	Bcc
    email.addBcc(from);
    //
    return email;
}
Also used : Server(org.compiere.interfaces.Server) 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