use of org.compiere.model.MUserMail in project adempiere by adempiere.
the class AssetDelivery method deliverIt.
// sendNoGuaranteeMail
/**************************************************************************
* Deliver Asset
* @param A_Asset_ID asset
* @return message - delivery errors start with **
*/
private String deliverIt(int A_Asset_ID) {
log.fine("A_Asset_ID=" + A_Asset_ID);
long start = System.currentTimeMillis();
//
MAsset asset = new MAsset(getCtx(), A_Asset_ID, get_TrxName());
if (asset.getAD_User_ID() == 0)
return "** No Asset User";
MUser user = new MUser(getCtx(), asset.getAD_User_ID(), get_TrxName());
if (user.getEMail() == null || user.getEMail().length() == 0)
return "** No Asset User Email";
if (asset.getProductR_MailText_ID() == 0)
return "** Product Mail Text";
if (m_MailText == null || m_MailText.getR_MailText_ID() != asset.getProductR_MailText_ID())
m_MailText = new MMailText(getCtx(), asset.getProductR_MailText_ID(), get_TrxName());
if (m_MailText.getMailHeader() == null || m_MailText.getMailHeader().length() == 0)
return "** No Subject";
// Create Mail
EMail email = m_client.createEMail(user.getEMail(), null, null);
if (!email.isValid()) {
asset.setHelp(asset.getHelp() + " - Invalid EMail");
asset.setIsActive(false);
return "** Invalid EMail: " + user.getEMail();
}
if (m_client.isSmtpAuthorization())
email.createAuthenticator(m_client.getRequestUser(), m_client.getRequestUserPW());
m_MailText.setUser(user);
m_MailText.setPO(asset);
String message = m_MailText.getMailText(true);
if (m_MailText.isHtml() || m_AttachAsset)
email.setMessageHTML(m_MailText.getMailHeader(), message);
else {
email.setSubject(m_MailText.getMailHeader());
email.setMessageText(message);
}
if (m_AttachAsset) {
MProductDownload[] pdls = asset.getProductDownloads();
if (pdls != null) {
for (int i = 0; i < pdls.length; i++) {
URI url = pdls[i].getDownloadURL(m_client.getDocumentDir());
if (url != null)
email.addAttachment(url);
}
} else
log.warning("No DowloadURL for A_Asset_ID=" + A_Asset_ID);
}
String msg = email.send();
new MUserMail(m_MailText, asset.getAD_User_ID(), email).saveEx();
if (!EMail.SENT_OK.equals(msg))
return "** Not delivered: " + user.getEMail() + " - " + msg;
MAssetDelivery ad = confirmDelivery(asset, email, user.getAD_User_ID());
ad.saveEx();
asset.saveEx();
//
log.fine((System.currentTimeMillis() - start) + " ms");
// success
return user.getEMail() + " - " + asset.getProductVersionNo();
}
use of org.compiere.model.MUserMail 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.model.MUserMail 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();
}
use of org.compiere.model.MUserMail in project adempiere by adempiere.
the class EMailDialog method actionPerformed.
// getAttachment
/**************************************************************************
* Action Listener - Send email
*/
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
dispose();
if (getTo() == null || getTo().length() == 0) {
return;
}
// Send
if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
confirmPanel.getOKButton().setEnabled(false);
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()) {
ADialog.info(0, this, "MessageSent");
dispose();
} else
ADialog.error(0, this, "MessageNotSent", status);
} else
ADialog.error(0, this, "MessageNotSent", status);
//
confirmPanel.getOKButton().setEnabled(false);
setCursor(Cursor.getDefaultCursor());
} else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
dispose();
}
Aggregations