Last active
December 18, 2015 04:59
-
-
Save jdorrance/5729661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mavendc.cq.test.workflow.impl | |
import javax.servlet.Servlet; | |
import com.day.cq.mailer.MessageGateway | |
import com.day.cq.mailer.MessageGatewayService | |
import com.day.cq.commons.mail.MailTemplate; | |
import org.mavendc.cq.test.workflow.EmailTest | |
import javax.jcr.Session; | |
import org.apache.commons.mail.HtmlEmail; | |
import org.apache.commons.lang.text.StrLookup; | |
import org.apache.felix.scr.annotations.Component; | |
import org.apache.felix.scr.annotations.Properties; | |
import org.apache.felix.scr.annotations.Property; | |
import org.apache.felix.scr.annotations.Reference; | |
import org.apache.felix.scr.annotations.Service; | |
import org.apache.sling.api.resource.Resource; | |
import org.apache.sling.api.resource.ResourceResolver | |
import org.apache.sling.api.resource.ResourceResolverFactory | |
@Component | |
@Service | |
class EmailTestImpl implements EmailTest { | |
@Reference | |
private MessageGatewayService messageGatewayService | |
@Reference | |
private ResourceResolverFactory resFactory; | |
@Override | |
public boolean messageGatewayExists() { | |
return (messageGatewayService != null) | |
} | |
@Override | |
public boolean sendTestEmail(String emailAddress,String emailTemplatePath) { | |
def resolver = resFactory?.getAdministrativeResourceResolver(null) | |
Resource emailRes = resolver.getResource(emailTemplatePath) | |
MailTemplate temp = MailTemplate.create(emailRes.getPath(), emailRes.resourceResolver.adaptTo(javax.jcr.Session.class)) | |
def params = | |
[ | |
from:'noreply@mavendc.com', | |
to: emailAddress, | |
subject: 'email test subject', | |
body : 'email test body' | |
] | |
HtmlEmail email = temp.getEmail(StrLookup.mapLookup(params), HtmlEmail.class) | |
MessageGateway gateway = messageGatewayService.getGateway(HtmlEmail.class) | |
gateway.send(email) | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment