Skip to content

Commit

Permalink
added: mailing script
Browse files Browse the repository at this point in the history
  • Loading branch information
shivang0-0 committed May 3, 2024
1 parent 0ffd2f5 commit 4e5c2cd
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/screens/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _LoginPageState extends State<LoginPage> {
width: 315,
height: 65,
decoration: const BoxDecoration(
color: Colors.transparent
color: Colors.black
),
),
),
Expand Down
16 changes: 16 additions & 0 deletions scripts/mail-scripts/email_body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OSDHACK '24 - AR Code</title>
</head>
<body>
<h1>Ahoy OSDHACK Participants!</h1>
<p>Thank you for registering for OSDHACK '24. Below is your unique QR code for attendance:</p>
<img src="PATH_TO_QR_CODE" alt="AR Code">
<p>Please make sure to bring this code with you to the event.</p>
<p>For more information and updates, visit the <a href="https://hack.odsc.dev/">OSDHACK '24 website</a>.</p>
<p>Best regards,<br>OSDC</p>
</body>
</html>
7 changes: 7 additions & 0 deletions scripts/mail-scripts/emails.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"subscribers": [
"shivang.sharma2062@gmail.com",
"krishkushjain@gmail.com",
"rahulkalra045@gmail.com"
]
}
10 changes: 10 additions & 0 deletions scripts/mail-scripts/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/osdc/Mercurius

go 1.15

require (
github.com/yuin/goldmark v1.3.5
github.com/yuin/goldmark-meta v1.0.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
)
12 changes: 12 additions & 0 deletions scripts/mail-scripts/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5 h1:dPmz1Snjq0kmkz159iL7S6WzdahUTHnHB5M56WFVifs=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark-meta v1.0.0 h1:ScsatUIT2gFS6azqzLGUjgOnELsBOxMXerM3ogdJhAM=
github.com/yuin/goldmark-meta v1.0.0/go.mod h1:zsNNOrZ4nLuyHAJeLQEZcQat8dm70SmB2kHbls092Gc=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
102 changes: 102 additions & 0 deletions scripts/mail-scripts/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package main

import (
"bytes"
"encoding/json"
"fmt"
"html"
"html/template"
"io/ioutil"
"log"
"os"

"github.com/yuin/goldmark"
meta "github.com/yuin/goldmark-meta"
"github.com/yuin/goldmark/parser"
"gopkg.in/gomail.v2"
)

type subscriberList struct {
Subscribers []string `json:"subscribers"`
}

func main() {
markdown := goldmark.New(
goldmark.WithExtensions(
meta.Meta,
),
)

jsonFile, err := os.Open("emails.json")

if err != nil {
log.Print(err)
}

defer jsonFile.Close()

byteValue, _ := ioutil.ReadAll(jsonFile)

var list subscriberList

json.Unmarshal(byteValue, &list)

content, _ := ioutil.ReadFile("../../content/post/example.md")

var buf bytes.Buffer
context := parser.NewContext()
if err := markdown.Convert(content, &buf, parser.WithContext(context)); err != nil {
panic(err)
}
metaData := meta.Get(context)
title := metaData["title"]
str := fmt.Sprintf("%v", title)

t := template.New("template.html")
t, _ = t.ParseFiles("template.html")

var body bytes.Buffer

if err := t.Execute(&body, struct {
Content string
Title string
}{
Content: buf.String(),
Title: str,
}); err != nil {
log.Println(err)
}
html := html.UnescapeString(body.String())

send(html, list.Subscribers)
}

func send(body string, to []string) {
from := os.Getenv("MAIL_ID")
pass := os.Getenv("MAIL_PASSWORD")

d := gomail.NewDialer("smtp.gmail.com", 587, from, pass)
s, err := d.Dial()
if err != nil {
panic(err)
}

bodyContent, err := ioutil.ReadFile("email_body.html")
if err != nil {
log.Fatal(err)
}

m := gomail.NewMessage()
for _, r := range to {
fmt.Printf("Sending email to: %s\n", r)
m.SetHeader("From", from)
m.SetAddressHeader("To", r, r)
m.SetHeader("Subject", "OSDHACK '24 Attendance QR")
m.SetBody("text/html", string(bodyContent))

if err := gomail.Send(s, m); err != nil {
log.Printf("Could not send email to %q: %v", r, err)
}
m.Reset()
}
}
7 changes: 7 additions & 0 deletions scripts/mail-scripts/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<body style="background-color: powderblue">
<h2>{{.Title}}</h2>
<p>{{.Content}}</p>
</body>
</html>

0 comments on commit 4e5c2cd

Please sign in to comment.