Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Installation of AWS SDK and initial attempts to get it to send email. #2

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+109 −0
Split
View
@@ -5,6 +5,7 @@
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
View
@@ -15,8 +15,14 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
@@ -0,0 +1,5 @@
+#Fri Sep 09 23:12:07 NZST 2011
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
View
@@ -149,6 +149,11 @@
<version>2.5</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>com.amazonaws</groupId>
+ <artifactId>aws-java-sdk</artifactId>
+ <version>1.2.4</version>
+ </dependency>
</dependencies>
<build>
<finalName>policy-auction</finalName>
@@ -4,6 +4,7 @@
import net.retakethe.policyauction.annotations.PublicPage;
import net.retakethe.policyauction.entities.User;
+import net.retakethe.policyauction.services.SendEmail;
import org.apache.tapestry5.annotations.SessionState;
@@ -30,4 +31,38 @@ public String getUsername() {
return "";
}
}
+
+ /**
+ * test text insert from Michael
+ * @return String
+ * @deprecated
+ */
+ @Deprecated
+ public String getTestInsert()
+ {
+ return new String("Text insert from Michael");
+ }
+
+ /**
+ * basic function to call the SendEmail class
+ * The idea is that if I can call it here to send a simple "Straight from AWS SES"
+ * email, that will prove functionality, and then we can extend the basic class to
+ * send whatever content to whoever.
+ *
+ * This _seems_ to pick up the SendEMail class, but I haven't been able to
+ * track down what's happening there.
+ * - I cannot find the output from System.out.println(result) being called in SendEmail.SendMail()
+ * - I've attempted to convert the methods in SendEMail from 'void' output to String, and call the
+ * toString() on the SendEmailResult object and passing it up the chain to echo in the browser
+ * with no luck.
+ *
+ * It could be as simple as me not calling it properly and so there being no results to pass around.
+ *
+ * For what it's worth, the perl test files work fine in sending email.
+ */
+ public String getEmailTest()
+ {
+ new SendEmail();
+ return new String("Has an Email been sent?");
+ }
}
@@ -0,0 +1,54 @@
+/*
+ * sample code from
+ * https://forums.aws.amazon.com/message.jspa?messageID=219406
+ *
+ * as of 20110909, SES is still in the sandbox environment,
+ * michael@birks.co.nz and michael@michaelbirks.com are both verified emails.
+ */
+
+package net.retakethe.policyauction.services;
+
+import java.util.LinkedList;
+
+import com.amazonaws.auth.AWSCredentials;
+import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient;
+import com.amazonaws.services.simpleemail.model.Body;
+import com.amazonaws.services.simpleemail.model.Content;
+import com.amazonaws.services.simpleemail.model.Destination;
+import com.amazonaws.services.simpleemail.model.Message;
+import com.amazonaws.services.simpleemail.model.SendEmailRequest;
+import com.amazonaws.services.simpleemail.model.SendEmailResult;
+
+public class SendEmail
+{
+ public static final String ACCESS_KEY = "_INSERT_ACCESS_KEY_";
+ public static final String SECRET_KEY = "_INSERT_SECRET_KEY_";
+
+
+ public static void main(String args[]) {
+ String sender = "michael@birks.co.nz"; // should be verified email
+
+ LinkedList<String> recipients = new LinkedList<String>();
+ recipients.add("michael@michaelbirks.com"); // again a verified email, if you are in sandbox
+
+ SendMail(sender, recipients, "Straight from AWS SES", "Hey, did you know that this message was sent via Simple Email Service programmatically using AWS Java SDK.");
+ }
+
+ public static void SendMail(String sender, LinkedList<String> recipients, String subject, String body) {
+ Destination destination = new Destination(recipients);
+
+ Content subjectContent = new Content(subject);
+ Content bodyContent = new Content(body);
+ Body msgBody = new Body(bodyContent);
+ Message msg = new Message(subjectContent, msgBody);
+
+ SendEmailRequest request = new SendEmailRequest(sender, destination, msg);
+
+ AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
+ AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient(credentials);
+ SendEmailResult result = sesClient.sendEmail(request);
+
+ System.out.println(result);
+ }
+}
@@ -12,10 +12,13 @@
<p>
<t:pagelink page="user/UserIndex">Users</t:pagelink>
</p>
+ <p>${emailTest}</p>
+
<p:sidebar>
<p>${currentTime}</p>
+
<p>
[<t:pagelink page="Index">refresh</t:pagelink>]