Added basic mailing
This commit is contained in:
103
mail/index.gohtml
Normal file
103
mail/index.gohtml
Normal file
@@ -0,0 +1,103 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Document</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<style>
|
||||
* {
|
||||
font-family: Montserrat, sans-serif;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.container {
|
||||
margin: 5% auto;
|
||||
max-width: 90%;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.grid__item {
|
||||
background: #fff;
|
||||
border-radius: 0.5rem;
|
||||
padding: 1.5rem 1rem;
|
||||
box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2), -4px 0 4px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.article__title {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.article__time {
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.article__text {
|
||||
font-size: 1.125rem;
|
||||
margin: 1rem 0;
|
||||
line-height: 1.5rem;
|
||||
}
|
||||
|
||||
.card__detail {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.article__by {
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.article__url {
|
||||
text-decoration: none;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: rgb(35, 35, 163);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Today's Newsletter</h1>
|
||||
<div class="container">
|
||||
<div class="grid">
|
||||
{{ range .News }}
|
||||
<div class="grid__item" data-article-id="{{ .Id }}">
|
||||
<h2 class="article__title" data-article-title="">
|
||||
{{ .Title }}
|
||||
</h2>
|
||||
<small class="article__time" data-article-time="">Unix Epoch {{ .CreatedAt }}</small>
|
||||
<p class="article__text" data-article-text="">
|
||||
{{ .Text }}
|
||||
</p>
|
||||
<div class="card__detail">
|
||||
<h3 class="article__by" data-article-by="">written by: {{ .Author }}</h3>
|
||||
<a class="article__url" data-article-url-="" href="{{ .Url }}" target="_blank">Read more</a>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
70
mail/mail.go
Normal file
70
mail/mail.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package mail
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/ses"
|
||||
)
|
||||
|
||||
const CharSet = "UTF-8"
|
||||
|
||||
func SendNewsletter(body string) {
|
||||
sess, err := session.NewSession(&aws.Config{
|
||||
Region: aws.String(os.Getenv("REGION"))},
|
||||
)
|
||||
|
||||
svc := ses.New(sess)
|
||||
|
||||
input := &ses.SendEmailInput{
|
||||
Destination: &ses.Destination{
|
||||
CcAddresses: []*string{},
|
||||
ToAddresses: []*string{
|
||||
aws.String(os.Getenv("RECIPIENT")),
|
||||
},
|
||||
},
|
||||
Message: &ses.Message{
|
||||
Body: &ses.Body{
|
||||
Html: &ses.Content{
|
||||
Charset: aws.String(CharSet),
|
||||
Data: aws.String(body),
|
||||
},
|
||||
Text: &ses.Content{
|
||||
Charset: aws.String(CharSet),
|
||||
Data: aws.String(body),
|
||||
},
|
||||
},
|
||||
Subject: &ses.Content{
|
||||
Charset: aws.String(CharSet),
|
||||
Data: aws.String("HackerNewsLetter"),
|
||||
},
|
||||
},
|
||||
Source: aws.String(os.Getenv("SENDER")),
|
||||
}
|
||||
|
||||
result, err := svc.SendEmail(input)
|
||||
|
||||
if err != nil {
|
||||
if aerr, ok := err.(awserr.Error); ok {
|
||||
switch aerr.Code() {
|
||||
case ses.ErrCodeMessageRejected:
|
||||
fmt.Println(ses.ErrCodeMessageRejected, aerr.Error())
|
||||
case ses.ErrCodeMailFromDomainNotVerifiedException:
|
||||
fmt.Println(ses.ErrCodeMailFromDomainNotVerifiedException, aerr.Error())
|
||||
case ses.ErrCodeConfigurationSetDoesNotExistException:
|
||||
fmt.Println(ses.ErrCodeConfigurationSetDoesNotExistException, aerr.Error())
|
||||
default:
|
||||
fmt.Println(aerr.Error())
|
||||
}
|
||||
} else {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Email sent with messageId " + *result.MessageId)
|
||||
}
|
||||
Reference in New Issue
Block a user