-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 64: Use mailgun to send email when user volunteers for a project
- Loading branch information
Showing
7 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
src/main/java/org/seattlevoluntech/SeattlevoluntechAppConfig.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.seattlevoluntech; | ||
|
||
import org.seattlevoluntech.Utilities.EmailUtility; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class SeattlevoluntechAppConfig { | ||
|
||
// Bean configuration for Mail Sender | ||
|
||
/** | ||
* Domain for mailgun mail sender api | ||
*/ | ||
@Value(value = "${mailgun.domain}") | ||
private String mailgunDomain; | ||
|
||
/** | ||
* API key required to send emails through mailgun | ||
*/ | ||
@Value(value = "${mailgun.api.key}") | ||
private String mailgunApiKey; | ||
|
||
@Bean | ||
public EmailUtility emailUtility() { | ||
return new EmailUtility(mailgunDomain, mailgunApiKey); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/seattlevoluntech/Utilities/EmailUtility.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.seattlevoluntech.Utilities; | ||
|
||
import com.mashape.unirest.http.HttpResponse; | ||
import com.mashape.unirest.http.JsonNode; | ||
import com.mashape.unirest.http.Unirest; | ||
import com.mashape.unirest.http.exceptions.UnirestException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.seattlevoluntech.models.Email; | ||
|
||
@RequiredArgsConstructor | ||
public class EmailUtility { | ||
private final String DOMAIN; | ||
private final String API_KEY; | ||
|
||
public JsonNode SendSimpleMessage(Email email) throws UnirestException { | ||
HttpResponse<JsonNode> request = Unirest.post("https://api.mailgun.net/v3/" + DOMAIN + "/messages") | ||
.basicAuth("api", API_KEY) | ||
.field("from", email.getFrom()) | ||
.field("to", email.getTo()) | ||
.field("subject", email.getSubject()) | ||
.field("text", email.getMessage()) | ||
.asJson(); | ||
return request.getBody(); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.seattlevoluntech.models; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class Email { | ||
private String from; | ||
private String to; | ||
private String subject; | ||
private String message; | ||
} |
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
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