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;
}
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();
}
Aggregations