コード例 #1
0
func sendResetKey(svc *ses.SES, reset *ResetMessage) error {

	params := &ses.SendEmailInput{
		Destination: &ses.Destination{ // Required
			ToAddresses: []*string{
				aws.String(reset.To),
			},
		},
		Message: &ses.Message{ // Required
			Body: &ses.Body{ // Required
				Text: &ses.Content{
					Data:    aws.String(reset.Key), // Required
					Charset: aws.String("utf-8"),
				},
			},
			Subject: &ses.Content{ // Required
				Data:    aws.String(reset.Key),
				Charset: aws.String("utf-8"),
			},
		},
		Source: aws.String(reset.From),
		ReplyToAddresses: []*string{
			aws.String(reset.From),
			// More values...
		},
	}

	resp, err := svc.SendEmail(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		log.Error(err.Error())
		return err
	} else {
		log.Info("ses response: %v", resp)

		return nil
	}
}
コード例 #2
0
func ensureSESRuleSetName(ruleSetName string, svc *ses.SES, logger *logrus.Logger) error {
	describeInput := &ses.DescribeReceiptRuleSetInput{
		RuleSetName: aws.String(ruleSetName),
	}
	var opError error
	describeRuleSet, describeRuleSetErr := svc.DescribeReceiptRuleSet(describeInput)
	if nil != describeRuleSetErr {
		if strings.Contains(describeRuleSetErr.Error(), "RuleSetDoesNotExist") {
			createRuleSet := &ses.CreateReceiptRuleSetInput{
				RuleSetName: aws.String(ruleSetName),
			}
			logger.WithFields(logrus.Fields{
				"createRuleSet": createRuleSet,
			}).Info("Creating Sparta SES Rule set")
			_, opError = svc.CreateReceiptRuleSet(createRuleSet)
		}
	} else {
		logger.WithFields(logrus.Fields{
			"describeRuleSet": describeRuleSet,
		}).Info("Sparta SES Rule Set already exists")
	}
	return opError
}