Skip to content

Commit 4e5c2cd

Browse files
committed
added: mailing script
1 parent 0ffd2f5 commit 4e5c2cd

File tree

7 files changed

+155
-1
lines changed

7 files changed

+155
-1
lines changed

lib/screens/login_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class _LoginPageState extends State<LoginPage> {
5656
width: 315,
5757
height: 65,
5858
decoration: const BoxDecoration(
59-
color: Colors.transparent
59+
color: Colors.black
6060
),
6161
),
6262
),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>OSDHACK '24 - AR Code</title>
7+
</head>
8+
<body>
9+
<h1>Ahoy OSDHACK Participants!</h1>
10+
<p>Thank you for registering for OSDHACK '24. Below is your unique QR code for attendance:</p>
11+
<img src="PATH_TO_QR_CODE" alt="AR Code">
12+
<p>Please make sure to bring this code with you to the event.</p>
13+
<p>For more information and updates, visit the <a href="https://hack.odsc.dev/">OSDHACK '24 website</a>.</p>
14+
<p>Best regards,<br>OSDC</p>
15+
</body>
16+
</html>

scripts/mail-scripts/emails.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"subscribers": [
3+
"shivang.sharma2062@gmail.com",
4+
"krishkushjain@gmail.com",
5+
"rahulkalra045@gmail.com"
6+
]
7+
}

scripts/mail-scripts/go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/osdc/Mercurius
2+
3+
go 1.15
4+
5+
require (
6+
github.com/yuin/goldmark v1.3.5
7+
github.com/yuin/goldmark-meta v1.0.0 // indirect
8+
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
9+
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
10+
)

scripts/mail-scripts/go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
2+
github.com/yuin/goldmark v1.3.5 h1:dPmz1Snjq0kmkz159iL7S6WzdahUTHnHB5M56WFVifs=
3+
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
4+
github.com/yuin/goldmark-meta v1.0.0 h1:ScsatUIT2gFS6azqzLGUjgOnELsBOxMXerM3ogdJhAM=
5+
github.com/yuin/goldmark-meta v1.0.0/go.mod h1:zsNNOrZ4nLuyHAJeLQEZcQat8dm70SmB2kHbls092Gc=
6+
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
7+
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
10+
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
11+
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
12+
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

scripts/mail-scripts/main.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"html"
8+
"html/template"
9+
"io/ioutil"
10+
"log"
11+
"os"
12+
13+
"github.com/yuin/goldmark"
14+
meta "github.com/yuin/goldmark-meta"
15+
"github.com/yuin/goldmark/parser"
16+
"gopkg.in/gomail.v2"
17+
)
18+
19+
type subscriberList struct {
20+
Subscribers []string `json:"subscribers"`
21+
}
22+
23+
func main() {
24+
markdown := goldmark.New(
25+
goldmark.WithExtensions(
26+
meta.Meta,
27+
),
28+
)
29+
30+
jsonFile, err := os.Open("emails.json")
31+
32+
if err != nil {
33+
log.Print(err)
34+
}
35+
36+
defer jsonFile.Close()
37+
38+
byteValue, _ := ioutil.ReadAll(jsonFile)
39+
40+
var list subscriberList
41+
42+
json.Unmarshal(byteValue, &list)
43+
44+
content, _ := ioutil.ReadFile("../../content/post/example.md")
45+
46+
var buf bytes.Buffer
47+
context := parser.NewContext()
48+
if err := markdown.Convert(content, &buf, parser.WithContext(context)); err != nil {
49+
panic(err)
50+
}
51+
metaData := meta.Get(context)
52+
title := metaData["title"]
53+
str := fmt.Sprintf("%v", title)
54+
55+
t := template.New("template.html")
56+
t, _ = t.ParseFiles("template.html")
57+
58+
var body bytes.Buffer
59+
60+
if err := t.Execute(&body, struct {
61+
Content string
62+
Title string
63+
}{
64+
Content: buf.String(),
65+
Title: str,
66+
}); err != nil {
67+
log.Println(err)
68+
}
69+
html := html.UnescapeString(body.String())
70+
71+
send(html, list.Subscribers)
72+
}
73+
74+
func send(body string, to []string) {
75+
from := os.Getenv("MAIL_ID")
76+
pass := os.Getenv("MAIL_PASSWORD")
77+
78+
d := gomail.NewDialer("smtp.gmail.com", 587, from, pass)
79+
s, err := d.Dial()
80+
if err != nil {
81+
panic(err)
82+
}
83+
84+
bodyContent, err := ioutil.ReadFile("email_body.html")
85+
if err != nil {
86+
log.Fatal(err)
87+
}
88+
89+
m := gomail.NewMessage()
90+
for _, r := range to {
91+
fmt.Printf("Sending email to: %s\n", r)
92+
m.SetHeader("From", from)
93+
m.SetAddressHeader("To", r, r)
94+
m.SetHeader("Subject", "OSDHACK '24 Attendance QR")
95+
m.SetBody("text/html", string(bodyContent))
96+
97+
if err := gomail.Send(s, m); err != nil {
98+
log.Printf("Could not send email to %q: %v", r, err)
99+
}
100+
m.Reset()
101+
}
102+
}

scripts/mail-scripts/template.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body style="background-color: powderblue">
4+
<h2>{{.Title}}</h2>
5+
<p>{{.Content}}</p>
6+
</body>
7+
</html>

0 commit comments

Comments
 (0)