This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Working with Emails in VerticalResponse

The sendEmail operation creates and launches an email. It creates the email in text or HTML format and either sends or schedules it.

sendEmail
<verticalresponse.sendEmail>
	<region>{$ctx:region}</region>
    <streetAddress>{$ctx:streetAddress}</streetAddress>
    <message>{$ctx:message}</message>
    <fromLabel>{$ctx:fromLabel}</fromLabel>
    <postalCode>{$ctx:postalCode}</postalCode>
    <replyTo>{$ctx:replyTo}</replyTo>
    <subject>{$ctx:subject}</subject>
    <unsubscribeMessage>{$ctx:unsubscribeMessage}</unsubscribeMessage>
    <company>{$ctx:company}</company>
    <name>{$ctx:name}</name>
    <locality>{$ctx:locality}</locality>
    <from>{$ctx:from}</from>
	<listIds>{$ctx:listIds}</listIds>
	<scheduledAt>{$ctx:scheduledAt}</scheduledAt>
</verticalresponse.sendEmail>
Properties
  • region: Required - Region of the sender's address.
  • streetAddress: Required - Street address of the sender.
  • message: The body of the message.
  • fromLabel: Required - The From label for the email campaign.
  • postalCode: Required - Postal code of the sender.
  • replyTo: Required - The Reply-to email address in the email campaign.
  • subject: The subject of the email campaign.
  • unsubscribeMessage: Required - The unsubscribe message for the email campaign. This message is required by the law. The unsubscribe message should contain the {UNSUBSCRIBE_LINK}
  • company: The name of the company.
  • name: The name of the email campaign.
  • locality: Required - Locality of the sender.
  • from: Required - The address from which the email campaign will be sent.
  • listIds: Required - Array of list IDs to send the email to. Maximum of 50 list IDs are allowed. 
  • scheduledAt: Optional - Date flag to specify when to send the email. If it is not present, the email will be sent as soon as possible. If the scheduledAt parameter is present and is a valid date in the future, the email will be scheduled to be sent on the given date.

Note

  • The user can set up the default from, fromLabel, replyTo, streetAddress, and unsubscribeMessage in the user's account in the Web application. In this case, the user does not need to pass in these parameters in the request. However, if these values do not exist either in the API request or in the user’s default preferences, the API will return an error. These fields cannot be null for compliance purposes. If null or empty values are passed in, the API will return an error and not create the email. 
  • On success, the API returns a URI of the email just created, and the status of the email is set to draft.
Sample request

Following is a sample REST request that can be handled by the sendEmail operation.

Sample Request for sendEmail
{
	"accessToken":"4hvyvjhuhw7ujcmaesq9sw5xkw9",
	"apiUrl":"https://vrapi.verticalresponse.com/api/v1",
	"region":"EU",
	"streetAddress":"qweqwe qw",
	"message":"<html><body>Hi</body></html>",
	"fromLabel":"User",
	"postalCode":"10400",
	"replyTo":"user@gmail.com",
	"subject":"test",
	"unsubscribeMessage":"",
	"company":"CompanyOne",
	"name":"user",
	"locality":"loc",
	"from":"user@gmail.com",
	"listIds":["1099511635539"],
	"scheduledAt":"2014-05-22T16:11:03Z"
}
Related VerticalResponse documentation

http://developer.verticalresponse.com/docs/read/api_reference/emails

Sample configuration

Following is a sample proxy service that illustrates how to connect to VerticalResponse with the init operation and use the sendEmail operation. The sample request for this proxy can be found in sendEmail sample request.

As a best practice, create a separate sequence for handling the response payload for errors. In the following sample, this sequence is "faultHandlerSeq". For more information, see Configuring the VerticalResponse Fault Handler Sequence.

Sample Proxy
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="verticalresponse_sendEmail" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
	 <target>
	 <inSequence onError="faultHandlerSeq" >
      <property name="accessToken" expression="json-eval($.accessToken)"/>
      <property name="apiUrl" expression="json-eval($.apiUrl)"/>
      <property name="region" expression="json-eval($.region)"/>
      <property name="streetAddress" expression="json-eval($.streetAddress)"/>
      <property name="message" expression="json-eval($.message)"/>
      <property name="fromLabel" expression="json-eval($.fromLabel)"/>
      <property name="postalCode" expression="json-eval($.postalCode)"/>
      <property name="replyTo" expression="json-eval($.replyTo)"/>
      <property name="subject" expression="json-eval($.subject)"/>
      <property name="unsubscribeMessage" expression="json-eval($.unsubscribeMessage)"/>
      <property name="company" expression="json-eval($.company)"/>
      <property name="name" expression="json-eval($.name)"/>
      <property name="locality" expression="json-eval($.locality)"/>
      <property name="from" expression="json-eval($.from)"/>
	  <property name="listIds" expression="json-eval($.listIds)"/> 
      <property name="scheduledAt" expression="json-eval($.scheduledAt)"/> 
      <verticalresponse.init>
         <accessToken>{$ctx:accessToken}</accessToken>
         <apiUrl>{$ctx:apiUrl}</apiUrl>
      </verticalresponse.init>
      <verticalresponse.sendEmail>
         <region>{$ctx:region}</region>
         <streetAddress>{$ctx:streetAddress}</streetAddress>
         <message>{$ctx:message}</message>
         <fromLabel>{$ctx:fromLabel}</fromLabel>
         <postalCode>{$ctx:postalCode}</postalCode>
         <replyTo>{$ctx:replyTo}</replyTo>
         <subject>{$ctx:subject}</subject>
         <unsubscribeMessage>{$ctx:unsubscribeMessage}</unsubscribeMessage>
         <company>{$ctx:company}</company>
         <name>{$ctx:name}</name>
         <locality>{$ctx:locality}</locality>
         <from>{$ctx:from}</from>
		 <listIds>{$ctx:listIds}</listIds>
		 <scheduledAt>{$ctx:scheduledAt}</scheduledAt>
      </verticalresponse.sendEmail>
	  <filter source="$axis2:HTTP_SC" regex="^[^2][0-9][0-9]">
            <then>
               <switch source="$axis2:HTTP_SC">
                 <case regex="401">
                     <property name="ERROR_CODE" value="600401"/>	 
					 <property name="ERROR_MESSAGE" expression="json-eval($.error.message)"/>
                     <property name="error_description" expression="json-eval($.error.url)"/>
                  </case>
                  <case regex="404">
                     <property name="ERROR_CODE" value="600404"/>					  
					 <property name="ERROR_MESSAGE" expression="json-eval($.error.message)"/>
                     <property name="error_description" expression="json-eval($.error.url)"/>
                  </case>
				  <case regex="403">
                     <property name="ERROR_CODE" value="600403"/>
					 <property name="ERROR_MESSAGE" expression="json-eval($.error.message)"/>
                     <property name="error_description" expression="json-eval($.error.url)"/>
                  </case> 			  
                  <case regex="400">
                     <property name="ERROR_CODE" value="600400"/>			 
					 <property name="ERROR_MESSAGE" expression="json-eval($.error.message)"/>
                     <property name="error_description" expression="json-eval($.error.url)"/>
                  </case>
                  <case regex="500">
                     <property name="ERROR_CODE" value="600500"/>  
					 <property name="ERROR_MESSAGE" expression="json-eval($.error.message)"/>
                     <property name="error_description" expression="json-eval($.error.url)"/>
                  </case>
                  <default> 
				     <property name="ERROR_CODE" expression="$axis2:HTTP_SC"/>
					 <property name="ERROR_MESSAGE" expression="json-eval($.error.message)"/>
                     <property name="error_description" expression="json-eval($.error.url)"/>
                  </default>
               </switch> 
			   <sequence key="faultHandlerSeq"/>
            </then>
         </filter> 
	   <respond/>
	 </inSequence>
	  <outSequence>
	    <send/>
	  </outSequence>
	 </target>
   <description/>
  </proxy>