It's only possible to track clicks in HTML emails.
How can I monitor the opens, clicks, and bounces from emails that I send using Amazon SES?
Sending email using the Amazon SES SMTP Interface
我使用configset 将事件发送到SNS 主题并将我的lambda 订阅到SNS topic,结果如下:
package main
import (
"fmt"
"gopkg.in/gomail.v2" //go get gopkg.in/gomail.v2
)
const (
Sender = "sender@example.com"
SenderName = "senders name"
Recipient = "recipient@example.com"
SmtpUser = "username"
SmtpPass = "password"
ConfigSet = "Engagement"
Host = "email-smtp.eu-central-1.amazonaws.com"
Port = 587
Subject = "Amazon SES Test (Gomail)"
HtmlBody = "<html><head><title>SES Sample Email</title></head><body>" +
"<h1>Amazon SES Test Email (Gomail)</h1>" +
"<p>This email was sent with " +
"<a ses:tags='product:book;genre:fiction;subgenre:scifi;type:newrelease;'href='https://aws.amazon.com/ses/'>Amazon SES</a> using " +
"the <a ses:tags='product:email;genre:test;subgenre:custom;type:gomail;'href='https://github.com/go-gomail/gomail/'>Gomail " +
"package</a> for <a href='https://golang.org/'>Go</a>.</p>" +
"</body></html>"
TextBody = "This email was sent with Amazon SES using the Gomail package."
Tags = "genre=test,genre2=test2"
CharSet = "UTF-8"
)
func main() {
m := gomail.NewMessage()
m.SetBody("text/html", HtmlBody)
m.AddAlternative("text/plain", TextBody)
m.SetHeaders(map[string][]string{
"From": {m.FormatAddress(Sender, SenderName)},
"To": {Recipient},
"Subject": {Subject},
"X-SES-CONFIGURATION-SET": {ConfigSet},
"X-SES-MESSAGE-TAGS": {Tags},
})
d := gomail.NewPlainDialer(Host, Port, SmtpUser, SmtpPass)
if err := d.DialAndSend(m); err != nil {
fmt.Println(err)
} else {
fmt.Println("Email sent!")
}
}
click event:
In [29]: click_event['click']
Out[29]:
{'timestamp': '2021-02-26T10:44:00.606Z',
'ipAddress': 'xx.xx.xx.xx',
'userAgent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15',
'link': 'https://aws.amazon.com/ses/',
'linkTags': {'product': ['book'],
'subgenre': ['scifi'],
'genre': ['fiction'],
'type': ['newrelease']}}
..
In [38]: click_event['mail']['tags']
Out[38]:
{'ses:operation': ['SendSmtpEmail'],
'ses:configuration-set': ['Engagement'],
'ses:source-ip': ['xx.xx.xx.xx'],
'ses:from-domain': ['example.com'],
'genre': ['test'],
'genre2': ['test2'],
'ses:caller-identity': ['ses-smtp-user']}
open_event
In [41]: open_event1['mail']['tags']
Out[41]:
{'ses:operation': ['SendSmtpEmail'],
'ses:configuration-set': ['Engagement'],
'ses:source-ip': ['xx.xx.xx.xx'],
'ses:from-domain': ['example.com'],
'genre': ['test'],
'genre2': ['test2'],
'ses:caller-identity': ['ses-smtp-user']}
收到的电子邮件: