Generate HTML formatted emails with Peoplesoft data elements - peoplesoft

I am trying to generate an App Engine program that will generate emails to employees with an upcoming employment anniversary (i.e. 5 years, 10 years, etc..) and display a sort of Countdown timer in the body of the email that has the Days remaining until their anniversary. I was thinking of using the MCF class framework in an App Engine program to do this. I will use the SERVICE_DT field from the PS_EMPLOYEES table to get the users in scope for an anniversary. I wanted to know how I can use PeopleCode to map the data elements (i.e. SERVICE_DT) into an HTML element that will display in the email. Any help on this or code examples would be helpful. Thanks in advance.

I actually have created this kind of functionality in the past, except it wasn't intended for the employee with the anniversary. It worked for both Birthdays and Anniversaries, and it was used to notify HR, managers, etc. of upcoming events.
First you want to store an email template. This could be done in delivered workflow template pages or in a custom record.
In the template, you can include variables that your AppEngine program will replace. If this is going to just be for a single employee, it would be something like:
Dear $FirstName,
We are excited that your $Number anniversary will be on $Date.
Then in your code, you would read the template into a variable. And then substitute the values:
$template = Substitute($template, "$FirstName", &FirstName);
$template = Substitute($template, "$Number", &WhichAnniversary);
$template = Substitute($template, "$Date", &AnniversaryDate);
Then you would send the $template as the body of the email.
If you are using HTML emails, you could also send a list, just using one variable like $table in the template, and then build and HTLM Table in your AppEngine and substitute the variable like:
$template = Substitute($template, "$table", &table);

Related

Mail Merge Feature for a CRM web-app made in asp.NET

We're working on a web based CRM for my company in ASP.net. I frequently have to send newsletters to all of my customers, and it becomes tedious to manually copy all of their addresses. What I would like is a feature to send one mail to all of my customers, taking their addresses from our contacts database, similar to a mail merge.
My developer said that he can do this for Emails, but not for physical mail. His reasoning behind this is that he can write a script that sends the mails to all customers one by one, but he can only give one single print command, which would only be able to print the current contents of the page. Therefore, he would not be able to print the individual letters for all of the customers.
Does anyone have ideas on how this would be possible? E.g. printing the page in such a way that each letter would be printed on a seperate page, or another way to automatically print all of the letters (with the mailmerged fields)?
Any help will be appreciated. If you require more details, please tell me.
A webpage is not the right solution to physically print letters. What you need to produce is a report that would generate a PDF file. This report will generate a PDF document with a different customer address on each page. Try using Microsoft Reporting Services, it is included in SQL Server. Crystal Reports is also a popular reporting solution too.
Also, you will have a hard time printing the stylized contents of your nice looking e-mail in the reporting solutions mentioned above. Consider using the report only as the cover letter of your mail piece.
One possible solution is to use 3rd party library for creation of individual letters for your customers. Docentric Toolkit is .NET tool that solves exactly your problem. We are using it for creating individual letters for customers and they all are merged in one file so that printing is done only once. Users can even create or change template documents.
Next you would have to create a template document in MS Word where you would include fixed content and placeholders for variable content which would be filled in at runtime with customer information.
After processing the data in .NET application you merge the data with the template document (see code snippet below). Your final document will be one file with letters for your customers, each on its own page. This file can then be sent to the printer with one print command.
I am attaching a code snippet of a Main method of the sample console application. The project has references to Entity Framework and Docentric’s dlls and uses entity model of Northwind database.
As you can see, it is really easy to prepare the data and merge it with template document. Solution is suitable for ASP.NET and MVC applications because you don’t need Microsoft Office installed on the server.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Docentric.Word;
namespace DisplayCustomers
{
class Program
{
static void Main(string[] args)
{
// first we read customers - in the example we select only customers
// from USA and Canada and order them by country and customer name
List<Customers> customerList = new List<Customers>();
using (var db = new NORTHWNDEntities())
{
customerList = db.Customers
.OrderBy(o => o.Country)
.ThenBy(o => o.CompanyName)
.Where(w => w.Country == "USA" || w.Country == "Canada")
.ToList();
}
// next we merge customers data with the template and generate final document;
string templateDoc = #"C:\Test\Templates\CustomerLetter1_templ.docx";
string outputDoc = #"C:\Test\FinishedLetters\CustomerLetters1.docx";
DocumentGenerator dg = new DocumentGenerator(customerList);
DocumentGenerationResult result = dg.GenerateDocument(templateDoc, outputDoc);
}
}
}

Contact form 7 plugin wordpress - How to send email of filled values only

I have a form that has some optional fields but if a user doesn't fill them out the label of the input will be sent in the email and they will be empty. so for example if a user doesn't enter a city field the email will say City:
Is there a way to set conditionals where if a user doesn't enter optional fields the label wont be sent?
http://wordpress.org/plugins/contact-form-7/
Short answer: yes, but.
Long answer: Wpcf7 has events for on send and others that you can hook into to extract and manipulate the data it has at the time. It's not a well documented aspect of the plug in, because it's really intended for the developer themselves to use, but you can write add_hook commands into your functions . php file and then use your own functions to change the output.
I think the send hook is called "wpcf7_send" so you can write a function like this:
function beforesend($obj) {
//manipulation of message here
}
add_hook('wpcf7_send', 'beforesend');
It's only a starting point but by exploring a bit you can find the hook names, and class structures you need.

Wordpress Plug-in - Trigger e-mail based on a specific date

I currently have a registration form for people to signup and pick a date for an "appointment". They get sent an e-mail right after filling it up with the details. I need another e-mail to be sent a day before their chosen date to remind them, but that can't be fulfilled by plugins I currently have.
Does anyone know of any Wordpress plug-in that allows the sending of an e-mail message (with a template and user specific data) based on a specified date?
Any piece of information or advice would be highly appreciated. Thanks!
How I would approach this would be with Wordpresses event scheduling. When a user submits the form to schedule their appointment, set a new action for the reminder email:
// Set this when you send the confirmation email
// Set the $unix_timestamp to be whenever you want the reminder to be sent.
// Args can be an array of the data you will need. Such as the users email/appt date
$args = array(
'email' => 'email#email.com'
);
wp_schedule_single_event($unix_timestamp, 'set_reminder', $args);
Now we have to catch that, and create a function to actually create and send the email (assuming you use a similar process):
add_action('set_reminder','do_reminder');
function do_reminder($args) {
// $email = $args['email'], etc.
// send reminder email.
}
I recommend Wysija Newsletters. You http://wordpress.org/extend/plugins/wysija-newsletters/. You can use template and user specific data in your email with this plugin.
If you are comfortable with writing your own code(I guess you are more or less ok with that), you can use the WordPress Schedule API(okay, maybe that's not the official name, but it works). Basically it's kind of a cron-job, but for WordPress. It has one downside though - it will only trigger on time, if WordPress is rendered(in other words accessed, so that it's code will execute). That can be easily fixed by adding a simple cron-job to your hosting account, that will simply access your home page every X hours.
You can find useful information on the API here.
Basically what you should have inside of your scheduled function is to get the records of people that should be sent reminder emails(you should probably store additional information about whether a reminder email has been sent or not) and send them the emails. I don't know what is the way you're storing the information from the registration form, but if you are using a Custom Post Type, then things should be pretty easy for you.

WordPress Email, Custom Post types and Email Subscriptions

I have something a client wants me to build, and I can with wp_mail, but I am wondering if how it should be built is fessable - no they dont want to use third party websites or software.
Essentially a widget will take in the clients email address, with this we can:
Have some kind of interface so we can say that send out 5, 10, 15 posts of category x, y, x on a daily, weekly or monthly basis
Thats not hard, but the question is: how would I store the emails that come in? a new column?
Use these emails and a custom post type to create email templates, newsletters and so on that could be sent to a set of emails (in this case all emails stored for now) at a specified time.
This one isn't hard either, its the custom post type part, how would I create a custom post type that when a post is published the post is not published the same way a post is, or a page. but instead its stored like one, but I can use its content in an email body instead of displaying it like a post or page.
essentially I shouldn't be able to go to:
site.come/email_templates/post_id
So the second one is a bit more complicated but I am wondering how you guys might approach this situation or idea.
Here are some thoughts when it comes to the e-mail subscription part. As for the custom post types - I don't have much experience with those, sorry :)
If you want a quick and easy solution for the e-mail subscriptions, create a wp option (see http://codex.wordpress.org/Function_Reference/add_option) that is essentially a hash table that maps categories to keys in the table.
For each category in the hash table, store an array of userIDs and/or e-mails of the users that are subscribed to that category.
Once you have this data structure in place, it's fairly easy to manipulate and use in with wp_mail. Here is some example code that I've written for one of my plugins:
$subscribers = get_option('subscribers');
$categories = get_the_category($post->ID);
if( !empty($categories) && !empty($subscribers)){
$emails = array();
//Go through each category and accumulate the necessary e-mail addresses
foreach($categories as $category){
$catID = $category->term_id;
if( !empty($subscribers[$catID]) ){
foreach($subscribers[$catID] as $userID => $trash){
$user = get_userdata($userID);
$userEmail = array( $userID => $user->user_email );
if( !in_array($userEmail, $emails) ){
$emails = $emails + $userEmail;
//you can use something like implode(", ", $emails)
//in the Bcc: part when you send out the e-mail.
}
}
}
}
}
Some things to note:
This is a quick and dirty solution. If the number of categories and number of subscribers grows big, you're better of creating a table in the database and maintaining it that way
Make sure to think of situations when categories are deleted (i.e. hook into actions when categories are deleted) and how that will affect your datastructure
The hash table approach works well assuming categories are NOT deleted/added frequently
Good luck!

Drupal module to control user post frequency?

We've been having a new type of spam-bot this week at PortableApps.com which posts at a rate of about 10 comments a minute and doesn't seem to stop - at least the first hour or so (we've always stopped it within that time so far). We've had them about a dozen times in the last week - sometimes stopping it at 50 or 60, sometimes up to 250 or 300. We're working to stop it and other spam bots as much as possible, but at the moment it's still a real pest.
I was wondering whether in the mean time whether there's any sort of module to control the frequency a user can post at to e.g. 50 an hour or something like 10 in an hour for new users. That at least would mean that instead of having to clear up 300 comments 50 at a time in admin/content/comment we'd have a smaller number to clear. (A module to add a page to delete all content by a user and block them would also be helpful!)
I believe that there's a plugin to do this available for WordPress, but can't find any such thing for Drupal.
For your second question, i would have a look at the code of the User Delete module (click).
The module also disables the user account and unpublished all nodes/comments from a certain user. By extending the code, you could easily create another possibility to unpublish + delete all nodes/comments from a certain user and blocking the account.
After the unpublish code in the module, you should just put delete code (in sql if the module is selecting by a sql-query or by using the drupal delete functions).
Another option would be so make a view (using the view module) only to be viewed by administrators, where you choose a certain user using the filters and then lists his/her posts. Then in the node-contenttype.tpl.php you place a button that calls a function which deletes all nodes/comments and the user.
First problem (post frequency)
I've been thinking about the comment post limit. If I remember correctly Drupal stores comments in a seperate table and has comment specific functions.
I'd create a new module and using the comment_nodeapi function i would check in the operation 'insert' how much comments the current user has already made within a certain timeframe.
To check this I would write a custom sql query on the database which takes the count of alle comments made by uid where the post_date is larger then NOW-1hour. If that count is larger then 10 or 15 or whatever post frequency you want then you give a message back to the user. You can retrieve the user id and name by using the global $user variable.
(example: print $user->name;)
You have to check on your own for the sql query but here's some code when you have the amount:
<?php
function comment_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case 'insert':
//PLACE HERE THE SQL TO GET THE COUNT
if($count > 15){
$repeat = FALSE;
$type = 'status'
drupal_set_message("You have reached the comment limit for this time.", $type, $repeat);
break;
}else{
db_query('INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) VALUES (%d, %d, NULL, %d, 0)', $node->nid, $node->changed, $node->uid);
break;
}
}
}
?>
(this code has not been tested so no guarantees, but this should put you on the right track)
I would suggest something like Mollom (from the creator of Drupal). It scans the message for known spam pattern/keywords/... and if this scan fails, it displays a CAPTCHA to the user to make sure that it's a real human that wants to enter content that has the same properties like spam.
They offer a free service and some paid solutions. We are using it for some customers and it's worth the money. It also integrates very well in Drupal.
Comment Limit is probably what you need.
http://drupal.org/project/spam
http://drupal.org/project/antispam - with akismet support

Resources