-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
2,377 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -31,6 +31,7 @@ jobs: | |
cognito | ||
containers | ||
dynamodb | ||
eventbridge | ||
fifoqueue | ||
github | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,2 @@ | ||
target/ | ||
node_modules/ |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Wing | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,47 @@ | ||
|
||
## Prerequisites | ||
|
||
* [winglang](https://winglang.io). | ||
|
||
For AWS, you need to have an AWS account and the AWS CLI installed. You'll also need to have [Terraform](https://developer.hashicorp.com/terraform/install) or [OpenTofu](https://opentofu.org/docs/intro/install/) installed to deploy the application. | ||
|
||
## Installation | ||
|
||
```sh | ||
npm i @winglibs/email | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
bring email; | ||
|
||
let email = new email.Email(sender: "[email protected]"); | ||
|
||
new cloud.Function(inflight () => { | ||
email.send( | ||
to: ["[email protected]"], | ||
subject: "My subject", | ||
text: "My content", | ||
html: "<h1>My content</h1>", // optional | ||
); | ||
}); | ||
``` | ||
|
||
### Simulator | ||
|
||
When using `email.Email` in the local simulator, emails are mocked and are emitted to the logs. | ||
A table showing all emails that have been sent can be viewed in the email resource's interaction panel. | ||
|
||
### AWS | ||
|
||
When compiled to AWS platforms, the email resource uses [Amazon SES](https://aws.amazon.com/ses/). | ||
For testing, we recommend using your own email address for `sender` since sender email addresses must be verified. | ||
When the application is deployed, an email will be sent to verify the configured `sender` address. | ||
|
||
By default, new AWS accounts are in the sandbox mode. This means emails can only be sent to verified addresses. It also limits the number of emails that can be sent. To send emails to other addresses, you need to request production access [here](https://docs.aws.amazon.com/ses/latest/dg/request-production-access.html). | ||
|
||
## License | ||
|
||
This library is licensed under the [MIT License](./LICENSE). |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,31 @@ | ||
import types from "./aws.extern"; | ||
import { SESv2Client, SendEmailCommand } from "@aws-sdk/client-sesv2"; | ||
|
||
export const _sendEmail: types["_sendEmail"] = async (sender, options) => { | ||
const ses = new SESv2Client(); | ||
let res = await ses.send(new SendEmailCommand({ | ||
Content: { | ||
Simple: { | ||
Body: { | ||
Text: { | ||
Data: options.text, | ||
Charset: "UTF-8", | ||
}, | ||
Html: { | ||
Data: options.html, | ||
Charset: "UTF-8", | ||
} | ||
}, | ||
Subject: { | ||
Data: options.subject, | ||
Charset: "UTF-8", | ||
} | ||
} | ||
}, | ||
Destination: { | ||
ToAddresses: options.to as string[], // cast from readonly string[] to string[] | ||
}, | ||
FromEmailAddress: sender, | ||
})); | ||
return res.MessageId; | ||
}; |
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,22 @@ | ||
bring cloud; | ||
bring expect; | ||
bring "./lib.w" as l; | ||
|
||
let email = new l.Email(sender: "[email protected]"); | ||
|
||
test "send email" { | ||
// sending an email with html | ||
email.send( | ||
to: ["[email protected]"], | ||
subject: "My subject", | ||
text: "My body", | ||
html: "<h1>My body</h1>", | ||
); | ||
|
||
// sending an email without html | ||
email.send( | ||
to: ["[email protected]"], | ||
subject: "My subject", | ||
text: "My body", | ||
); | ||
} |
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,27 @@ | ||
bring util; | ||
bring "./sim.w" as email_sim; | ||
bring "./tfaws.w" as email_tfaws; | ||
bring "./types.w" as types; | ||
|
||
pub class Email { | ||
inner: types.IEmail; | ||
new(props: types.EmailProps) { | ||
let target = util.env("WING_TARGET"); | ||
|
||
if target == "sim" { | ||
let email = new email_sim.Email_sim(props); | ||
email.addUI(this); | ||
this.inner = email; | ||
} else { | ||
this.inner = new email_tfaws.Email_tfaws(props); | ||
} | ||
|
||
nodeof(this.inner).hidden = true; | ||
nodeof(this).icon = "inbox"; | ||
nodeof(this).color = "pink"; | ||
} | ||
|
||
pub inflight send(options: types.SendEmailOptions): void { | ||
this.inner.send(options); | ||
} | ||
} |
Oops, something went wrong.