[ 1949329 ] Workflow sendMail doesn't handle html flag in mail template

This commit is contained in:
Heng Sin Low 2008-04-23 03:12:40 +00:00
parent 1315cc4757
commit 29d894b269
3 changed files with 187 additions and 41 deletions

View File

@ -17,16 +17,28 @@
*****************************************************************************/
package org.compiere.model;
import java.rmi.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import javax.mail.internet.*;
import java.io.*;
import java.io.File;
import java.rmi.RemoteException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import javax.mail.internet.InternetAddress;
import org.compiere.db.*;
import org.compiere.interfaces.*;
import org.compiere.util.*;
import org.compiere.db.CConnection;
import org.compiere.interfaces.Server;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.EMail;
import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.Language;
/**
* Client Model
@ -531,6 +543,21 @@ public class MClient extends X_AD_Client
*/
public boolean sendEMailAttachments (int AD_User_ID,
String subject, String message, Collection<File> attachments)
{
return sendEMailAttachments(AD_User_ID, subject, message, attachments, false);
}
/**
* 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();
@ -539,7 +566,7 @@ public class MClient extends X_AD_Client
log.warning("No EMail for recipient: " + to);
return false;
}
EMail email = createEMail(null, to, subject, message);
EMail email = createEMail(null, to, subject, message, html);
if (email == null)
return false;
email.addAttachments(attachments);
@ -553,19 +580,34 @@ public class MClient extends X_AD_Client
return false;
}
} // sendEMail
/**
* Send EMail from Request User - no trace
* @param to recipient email address
* @param subject subject
* @param message message
* @param attachment optional attachment
* @return true if sent
*/
public boolean sendEMail (String to,
String subject, String message, File attachment)
{
return sendEMail(to, subject, message, attachment, false);
}
/**
* Send EMail from Request User - no trace
* @param to recipient email address
* @param subject subject
* @param message message
* @param attachment optional attachment
* @param attachment optional attachment
* @param html
* @return true if sent
*/
public boolean sendEMail (String to,
String subject, String message, File attachment)
String subject, String message, File attachment, boolean html)
{
EMail email = createEMail(to, subject, message);
EMail email = createEMail(to, subject, message, html);
if (email == null)
return false;
if (attachment != null)
@ -593,6 +635,20 @@ public class MClient extends X_AD_Client
}
} // sendEMail
/**
* Send EMail from User
* @param from sender
* @param to recipient
* @param subject subject
* @param message message
* @param attachment optional attachment
* @return true if sent
*/
public boolean sendEMail (MUser from, MUser to,
String subject, String message, File attachment)
{
return sendEMail(from, to, subject, message, attachment, false);
}
/**
* Send EMail from User
@ -601,14 +657,17 @@ public class MClient extends X_AD_Client
* @param subject subject
* @param message message
* @param attachment optional attachment
* @param isHtml
* @return true if sent
*/
public boolean sendEMail (MUser from, MUser to,
String subject, String message, File attachment)
String subject, String message, File attachment, boolean isHtml)
{
EMail email = createEMail(from, to, subject, message);
if (email == null)
return false;
EMail email = createEMail(from, to, subject, message, isHtml);
if (email == null)
return false;
if (attachment != null)
email.addAttachment(attachment);
InternetAddress emailFrom = email.getFrom();
@ -675,16 +734,30 @@ public class MClient extends X_AD_Client
return false;
}
} // sendEmailNow
/************
* 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)
{
return createEMail(to, subject, message, false);
}
/************
* Create EMail from Request User
* @param to recipient
* @param subject sunject
* @param message nessage
* @param message nessage
* @param html
* @return EMail
*/
public EMail createEMail (String to,
String subject, String message)
String subject, String message, boolean html)
{
if (to == null || to.length() == 0)
{
@ -699,7 +772,9 @@ public class MClient extends X_AD_Client
try
{
if (server != null)
{ // See ServerBean
{ // See ServerBean
if (html && message != null)
message = EMail.HTML_MAIL_MARKER + message;
email = server.createEMail(getCtx(), getAD_Client_ID(),
to, subject, message);
}
@ -714,22 +789,37 @@ public class MClient extends X_AD_Client
if (email == null)
email = new EMail (this,
getRequestEMail(), to,
subject, message);
subject, message, html);
if (isSmtpAuthorization())
email.createAuthenticator (getRequestUser(), getRequestUserPW());
return email;
} // createEMail
/**
* Create EMail from User
* @param from optional sender
* @param to recipient
* @param subject sunject
* @param message nessage
* @return EMail
*/
public EMail createEMail (MUser from, MUser to,
String subject, String message)
{
return createEMail(from, to, subject, message, false);
}
/**
* Create EMail from User
* @param from optional sender
* @param to recipient
* @param subject sunject
* @param message nessage
* @param message nessage
* @param html
* @return EMail
*/
public EMail createEMail (MUser from, MUser to,
String subject, String message)
String subject, String message, boolean html)
{
if (to == null)
{
@ -741,19 +831,34 @@ public class MClient extends X_AD_Client
log.warning("No To address: " + to);
return null;
}
return createEMail (from, to.getEMail(), subject, message);
return createEMail (from, to.getEMail(), subject, message, html);
} // createEMail
/**
* Create EMail from User
* @param from optional sender
* @param to recipient
* @param subject sunject
* @param message nessage
* @return EMail
*/
public EMail createEMail (MUser from, String to,
String subject, String message)
{
return createEMail(from, to, subject, message, false);
}
/**
* Create EMail from User
* @param from optional sender
* @param to recipient
* @param subject sunject
* @param message nessage
* @param message nessage
* @param html
* @return EMail
*/
public EMail createEMail (MUser from, String to,
String subject, String message)
String subject, String message, boolean html)
{
if (to == null || to.length() == 0)
{
@ -779,7 +884,9 @@ public class MClient extends X_AD_Client
try
{
if (server != null)
{ // See ServerBean
{ // See ServerBean
if (html && message != null)
message = email.HTML_MAIL_MARKER + message;
email = server.createEMail(getCtx(), getAD_Client_ID(),
from.getAD_User_ID(),
to, subject, message);
@ -797,7 +904,7 @@ public class MClient extends X_AD_Client
from.getEMail(),
to,
subject,
message);
message, html);
if (isSmtpAuthorization())
email.createAuthenticator (from.getEMailUser(), from.getEMailUserPW());
return email;

View File

@ -45,6 +45,8 @@ import org.compiere.model.*;
*/
public final class EMail implements Serializable
{
//use in serverbean
public final static String HTML_MAIL_MARKER = "ContentType=text/html;";
/**
* Full Constructor
* @param client the client
@ -58,6 +60,21 @@ public final class EMail implements Serializable
{
this (client.getCtx(), client.getSMTPHost(), from, to, subject, message);
} // EMail
/**
* Full Constructor
* @param client the client
* @param from Sender's EMail address
* @param to Recipient EMail address
* @param subject Subject of message
* @param message The message
* @param html
*/
public EMail (MClient client, String from, String to,
String subject, String message, boolean html)
{
this (client.getCtx(), client.getSMTPHost(), from, to, subject, message, html);
} // EMail
/**
* Full Constructor
@ -69,7 +86,23 @@ public final class EMail implements Serializable
* @param message The message
*/
public EMail (Properties ctx, String smtpHost, String from, String to,
String subject, String message)
String subject, String message)
{
this(ctx, smtpHost, from, to, subject, message, false);
}
/**
* Full Constructor
* @param ctx context
* @param smtpHost The mail server
* @param from Sender's EMail address
* @param to Recipient EMail address
* @param subject Subject of message
* @param message The message
* @param html html email
*/
public EMail (Properties ctx, String smtpHost, String from, String to,
String subject, String message, boolean html)
{
setSmtpHost(smtpHost);
setFrom(from);
@ -80,7 +113,12 @@ public final class EMail implements Serializable
else
setSubject (subject);
if (message != null && message.length() > 0)
setMessageText (message);
{
if (html)
setMessageHTML(subject, message);
else
setMessageText (message);
}
m_valid = isValid (true);
} // EMail

View File

@ -1530,12 +1530,12 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
MClient client = MClient.get(doc.getCtx(), doc.getAD_Client_ID());
// Explicit EMail
sendEMail(client, 0, m_node.getEMail(), subject, message, pdf);
sendEMail(client, 0, m_node.getEMail(), subject, message, pdf, text.isHtml());
// Recipient Type
String recipient = m_node.getEMailRecipient();
// email to document user
if (recipient == null || recipient.length() == 0)
sendEMail(client, doc.getDoc_User_ID(), null, subject, message, pdf);
sendEMail(client, doc.getDoc_User_ID(), null, subject, message, pdf, text.isHtml());
else if (recipient.equals(MWFNode.EMAILRECIPIENT_DocumentBusinessPartner))
{
int index = m_po.get_ColumnIndex("AD_User_ID");
@ -1546,7 +1546,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
{
int AD_User_ID = ((Integer)oo).intValue();
if (AD_User_ID != 0)
sendEMail(client, AD_User_ID, null, subject, message, pdf);
sendEMail(client, AD_User_ID, null, subject, message, pdf, text.isHtml());
else
log.fine("No User in Document");
}
@ -1557,14 +1557,14 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
log.fine("No User Field in Document");
}
else if (recipient.equals(MWFNode.EMAILRECIPIENT_DocumentOwner))
sendEMail(client, doc.getDoc_User_ID(), null, subject, message, pdf);
sendEMail(client, doc.getDoc_User_ID(), null, subject, message, pdf, text.isHtml());
else if (recipient.equals(MWFNode.EMAILRECIPIENT_WFResponsible))
{
MWFResponsible resp = getResponsible();
if (resp.isInvoker())
sendEMail(client, doc.getDoc_User_ID(), null, subject, message, pdf);
sendEMail(client, doc.getDoc_User_ID(), null, subject, message, pdf, text.isHtml());
else if (resp.isHuman())
sendEMail(client, resp.getAD_User_ID(), null, subject, message, pdf);
sendEMail(client, resp.getAD_User_ID(), null, subject, message, pdf, text.isHtml());
else if (resp.isRole())
{
MRole role = resp.getRole();
@ -1572,7 +1572,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
{
MUser[] users = MUser.getWithRole(role);
for (int i = 0; i < users.length; i++)
sendEMail(client, users[i].getAD_User_ID(), null, subject, message, pdf);
sendEMail(client, users[i].getAD_User_ID(), null, subject, message, pdf, text.isHtml());
}
}
else if (resp.isOrganization())
@ -1581,7 +1581,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
if (org.getSupervisor_ID() == 0)
log.fine("No Supervisor for AD_Org_ID=" + m_po.getAD_Org_ID());
else
sendEMail(client, org.getSupervisor_ID(), null, subject, message, pdf);
sendEMail(client, org.getSupervisor_ID(), null, subject, message, pdf, text.isHtml());
}
}
} // sendEMail
@ -1594,9 +1594,10 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
* @param subject subject
* @param message message
* @param pdf attachment
* @param isHtml isHtml
*/
private void sendEMail (MClient client, int AD_User_ID, String email,
String subject, String message, File pdf)
String subject, String message, File pdf, boolean isHtml)
{
if (AD_User_ID != 0)
{
@ -1607,7 +1608,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
email = email.trim();
if (!m_emails.contains(email))
{
client.sendEMail(null, user, subject, message, pdf);
client.sendEMail(null, user, subject, message, pdf,isHtml);
m_emails.add(email);
}
}