Search in sources :

Example 1 with MandrillTemplatedMessageRequest

use of com.cribbstechnologies.clients.mandrill.model.MandrillTemplatedMessageRequest in project Java-Mandrill-Wrapper by cribbstechnologies.

the class MessagesTest method testSendTemplatedMessage.

@Test
public void testSendTemplatedMessage() {
    MandrillTemplatedMessageRequest request = new MandrillTemplatedMessageRequest();
    MandrillMessage message = new MandrillMessage();
    Map<String, String> headers = new HashMap<String, String>();
    message.setFrom_email(props.getProperty("email.from"));
    message.setFrom_name("Big Jimmy");
    message.setHeaders(headers);
    message.setSubject("This is the subject");
    MandrillRecipient[] recipients = new MandrillRecipient[] { new MandrillRecipient(props.getProperty("email.to.name1"), props.getProperty("email.to.address1")), new MandrillRecipient(props.getProperty("email.to.name2"), props.getProperty("email.to.address2")) };
    message.setTo(recipients);
    message.setTrack_clicks(true);
    message.setTrack_opens(true);
    String[] tags = new String[] { "tag1", "tag2", "tag3" };
    message.setTags(tags);
    request.setMessage(message);
    List<TemplateContent> content = new ArrayList<TemplateContent>();
    request.setTemplate_content(content);
    request.setTemplate_name("template2");
    List<MergeVar> globalMergeVars = new ArrayList<MergeVar>();
    globalMergeVars.add(new MergeVar("username", "bcribs"));
    globalMergeVars.add(new MergeVar("registration_url", "http://myserver.com/register?userid=bcribs"));
    message.setGlobal_merge_vars(globalMergeVars);
    try {
        messagesRequest.sendTemplatedMessage(request);
    } catch (RequestFailedException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) TemplateContent(com.cribbstechnologies.clients.mandrill.model.TemplateContent) MandrillTemplatedMessageRequest(com.cribbstechnologies.clients.mandrill.model.MandrillTemplatedMessageRequest) ArrayList(java.util.ArrayList) MandrillMessage(com.cribbstechnologies.clients.mandrill.model.MandrillMessage) RequestFailedException(com.cribbstechnologies.clients.mandrill.exception.RequestFailedException) MergeVar(com.cribbstechnologies.clients.mandrill.model.MergeVar) MandrillRecipient(com.cribbstechnologies.clients.mandrill.model.MandrillRecipient) Test(org.junit.Test)

Aggregations

RequestFailedException (com.cribbstechnologies.clients.mandrill.exception.RequestFailedException)1 MandrillMessage (com.cribbstechnologies.clients.mandrill.model.MandrillMessage)1 MandrillRecipient (com.cribbstechnologies.clients.mandrill.model.MandrillRecipient)1 MandrillTemplatedMessageRequest (com.cribbstechnologies.clients.mandrill.model.MandrillTemplatedMessageRequest)1 MergeVar (com.cribbstechnologies.clients.mandrill.model.MergeVar)1 TemplateContent (com.cribbstechnologies.clients.mandrill.model.TemplateContent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1