|
1 | 1 | ## The CDK Construct Library for AWS Simple Email Service
|
2 | 2 | This module is part of the [AWS Cloud Development Kit](https://github.com/awslabs/aws-cdk) project.
|
| 3 | + |
| 4 | +### Email receiving |
| 5 | +Create a receipt rule set with rules and actions: |
| 6 | +[example of setting up a receipt rule set](test/example.receiving.lit.ts) |
| 7 | + |
| 8 | +Alternatively, rules can be added to a rule set: |
| 9 | +```ts |
| 10 | +const ruleSet = new ses.ReceiptRuleSet(this, 'RuleSet'): |
| 11 | + |
| 12 | +const awsRule = ruleSet.addRule('Aws', { |
| 13 | + recipients: ['aws.com'] |
| 14 | +}); |
| 15 | +``` |
| 16 | + |
| 17 | +And actions to rules: |
| 18 | +```ts |
| 19 | +awsRule.addAction( |
| 20 | + new ses.ReceiptRuleSnsAction({ |
| 21 | + topic |
| 22 | + }); |
| 23 | +); |
| 24 | +``` |
| 25 | +When using `addRule`, the new rule is added after the last added rule unless `after` is specified. |
| 26 | + |
| 27 | +[More actions](test/integ.receipt.ts) |
| 28 | + |
| 29 | +#### Drop spams |
| 30 | +A rule to drop spam can be added by setting `dropSpam` to `true`: |
| 31 | + |
| 32 | +```ts |
| 33 | +new ses.ReceiptRuleSet(this, 'RuleSet', { |
| 34 | + dropSpam: true |
| 35 | +}); |
| 36 | +``` |
| 37 | + |
| 38 | +This will add a rule at the top of the rule set with a Lambda action that stops processing messages that have at least one spam indicator. See [Lambda Function Examples](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-action-lambda-example-functions.html). |
| 39 | + |
| 40 | +### Import and export receipt rule set and receipt rules |
| 41 | +Receipt rule sets and receipt rules can be exported: |
| 42 | + |
| 43 | +```ts |
| 44 | +const ruleSet = new ReceiptRuleSet(this, 'RuleSet'); |
| 45 | +const rule = ruleSet.addRule(this, 'Rule', { |
| 46 | + recipients: ['hello@mydomain.com'] |
| 47 | +}); |
| 48 | + |
| 49 | +const ruleSetRef = ruleSet.export(); |
| 50 | +const ruleRef = rule.export(); |
| 51 | +``` |
| 52 | + |
| 53 | +And imported: |
| 54 | +```ts |
| 55 | +const importedRuleSet = ses.ReceiptRuleSet.import(this, 'ImportedRuleSet', ruleSetRef); |
| 56 | + |
| 57 | +const importedRule = ses.ReceiptRule.import(this, 'ImportedRule', ruleRef); |
| 58 | + |
| 59 | +const otherRule = ses.ReceiptRule.import(this, 'OtherRule', { |
| 60 | + name: 'other-rule' |
| 61 | +}); |
| 62 | + |
| 63 | +importedRuleSet.addRule('New', { // This rule is added after the imported rule |
| 64 | + after: importedRule, |
| 65 | + recipients: ['mydomain.com'] |
| 66 | +}); |
| 67 | + |
| 68 | +importedRuleSet.addRule('Extra', { // Added after the 'New' rule |
| 69 | + recipients: ['extra.com'] |
| 70 | +}); |
| 71 | +``` |
| 72 | + |
| 73 | +### Receipt filter |
| 74 | +Create a receipt filter: |
| 75 | +```ts |
| 76 | +new ses.ReceiptFilter(this, 'Filter', { |
| 77 | + ip: '1.2.3.4/16' // Will be blocked |
| 78 | +}) |
| 79 | +``` |
| 80 | + |
| 81 | +A white list filter is also available: |
| 82 | +```ts |
| 83 | +new ses.WhiteListReceiptFilter(this, 'WhiteList', { |
| 84 | + ips: [ |
| 85 | + '10.0.0.0/16', |
| 86 | + '1.2.3.4/16', |
| 87 | + ] |
| 88 | +}); |
| 89 | +``` |
| 90 | +This will first create a block all filter and then create allow filters for the listed ip addresses. |
0 commit comments