HTML email sign-up page and unsubscribe link (ID:4716)
Project Creator: |
inyquist
FC Member For 6100 Days
Credits 295 Completed Proj. Num. 13 / 17 Total payment USD 14,785.00 Avg Daily Online 0.02 h (From 21/5/2007) Available on MSN/Skype Yes Last Login 10/29/2012 Peers Rating 100.00% |
---|---|
Budget: | Less than 250 |
Created: | 7/20/2008 2:52:33 PM EST |
Bidding Ends: | 7/27/2008 2:52:33 PM EST ( Expired ) |
Development Cycle: | 1 Days |
Bid Count: | 9
|
Average Bid: | 188.22 |
Project Description:
We are using Salesforce.com to launch some email campaigns. Our email has already been designed and built, however, we need to add an "Unsubscribe" link to the bottom of the email that will use .net and Salesforce API to allow recipients to remove themselves from our Salesforce.com database. We also need the following page on our website to use the Salesforce.com API to allow users to add themselves to our mailing list: http://www.nyquistdesign.com/html/mailing_list.html On this page, we would like to validate that the email address field has been filled out before allowing the user to continue (implemented as it is currently on that page). Newly added descriptions: Salesforce.com provides this sample code for the unsubscribe feature: Example 2: Handle Unsubscribe Email Companies that send marketing email to their customers and prospects need to provide a way to let the recipients unsubscribe. The following is an example of how an email service can process unsubscribe requests. The code searches the subject line of inbound email for the word "unsubscribe." If the word is found, the code finds all contacts and leads that match the From email address and sets the Email Opt Out field (HasOptedOutOfEmail) to True. Global class unsubscribe implements Messaging.inboundEmailHandler{ Global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope env ) { // Create an inboundEmailResult object for returning // the result of the email service. Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); // Create contact and lead lists to hold all the updated records. List<Contact> lc = new List <contact>(); List<Lead> ll = new List <lead>(); // Convert the subject line to lower case so the program can match on lower case. String mySubject = email.subject.toLowerCase(); // The search string used in the subject line. String s = 'unsubscribe'; // Check the variable to see if the word "unsubscribe" was found in the subject line. Boolean unsubMe; // Look for the word "unsubcribe" in the subject line. // If it is found, return true; otherwise, return false. unsubMe = mySubject.contains(s); // If unsubscribe is found in the subject line, enter the IF statement. if (unsubMe == true) { try { // Look up all contacts with a matching email address. for (Contact c : [Select Id, Name, Email, HasOptedOutOfEmail From Contact Where Email = :env.fromAddress And hasOptedOutOfEmail = false Limit 100]) { // Add all the matching contacts into the list. c.hasOptedOutOfEmail = true; lc.add(c); } // Update all of the contact records. update lc; } catch (System.QueryException e) { System.debug('Contact Query Issue: ' + e); } try { // Look up all leads matching the email address. for (Lead l : [Select Id, Name, Email, HasOptedOutOfEmail From Lead Where Email = :env.fromAddress And isConverted = false And hasOptedOutOfEmail = false Limit 100]) { // Add all the leads to the list. l.hasOptedOutOfEmail = true; ll.add(l); System.debug('Lead Object: ' + l); } // Update all lead records in the query. update ll; } catch (System.QueryException e) { System.debug('Lead Query Issue: ' + e); } System.debug('Found the unsubscribe word in the subject line.'); } else { System.debug('No Unsuscribe word found in the subject line.' ); } // Return True and exit. // True confirms program is complete and no emails // should be sent to the sender of the unsubscribe request. result.success = true; return result; } // The following test methods provide adequate code coverage. // There are two methods, one that does the testing // with a valid "unsubcribe" in the subject line // and one the does not contain "unsubscribe" in the // subject line. static testMethod void testUnsubscribe() { // Create a new email and envelope object. Messaging.InboundEmail email = new Messaging.InboundEmail() ; Messaging.InboundEnvelope env = new Messaging.InboundEnvelope(); // Create a new test lead and insert it in the test method. Lead l = new lead(firstName='John', lastName='Smith', Company='Salesforce', Email='user@acme.com', HasOptedOutOfEmail=false); insert l; // Create a new test contact and insert it in the test method. Contact c = new Contact(firstName='john', lastName='smith', Email='user@acme.com', HasOptedOutOfEmail=false); insert c; // Test with the subject that matches the unsubscribe statement. email.subject = 'test unsubscribe test'; env.fromAddress = 'user@acme.com'; // Call the class and test it with the data in the testMethod. unsubscribe unsubscribeObj = new unsubscribe(); unsubscribeObj.handleInboundEmail(email, env ); } static testMethod void testUnsubscribe2() { // Create a new email and envelope object. Messaging.InboundEmail email = new Messaging.InboundEmail(); Messaging.InboundEnvelope env = new Messaging.InboundEnvelope(); // Create a new test lead and insert it in the test method. Lead l = new lead(firstName='john', lastName='smith', Company='Salesforce', Email='user@acme.com', HasOptedOutOfEmail=false); insert l; // Create a new test contact and insert it in the test method. Contact c = new Contact(firstName='john', lastName='smith', Email='user@acme.com', HasOptedOutOfEmail=false); insert c; // Test with a subject that does not contain "unsubscribe." email.subject = 'test'; env.fromAddress = 'user@acme.com'; // Call the class and test it with the data in the test method. unsubscribe unsubscribeObj = new unsubscribe(); unsubscribeObj.handleInboundEmail(email, env ); } } |
|
Job Type | .NET |
Attached Files: | N/A |