From d45b55a2758f187d09619ad15c80fd1bc706ea18 Mon Sep 17 00:00:00 2001 From: Made Indra <42365530+madeindra@users.noreply.github.com> Date: Sun, 15 Oct 2023 16:08:13 +0700 Subject: [PATCH 1/3] feat: add invitation template --- emails/payment_success.ics | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 emails/payment_success.ics diff --git a/emails/payment_success.ics b/emails/payment_success.ics new file mode 100644 index 0000000..be8b08d --- /dev/null +++ b/emails/payment_success.ics @@ -0,0 +1,26 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//conf.teknologiumum.com//Teknologi Umum +CALSCALE:GREGORIAN +BEGIN:VTIMEZONE +TZID:Asia/Jakarta +LAST-MODIFIED:20230407T050750Z +TZURL:https://www.tzurl.org/zoneinfo-outlook/Asia/Jakarta +X-LIC-LOCATION:Asia/Jakarta +BEGIN:STANDARD +TZNAME:WIB +TZOFFSETFROM:+0700 +TZOFFSETTO:+0700 +DTSTART:19700101T000000 +END:STANDARD +END:VTIMEZONE +BEGIN:VEVENT +DTSTAMP:20231015T085408Z +UID:20231015T085408Z@teknologiumum.com +DTSTART;TZID=Asia/Jakarta:20231021T130000 +DTEND;TZID=Asia/Jakarta:20231021T190000 +SUMMARY:TeknumConf 2023 +URL:https://conf.teknologiumum.com/ +LOCATION:Kode Creative Hub\, Depok Town Square Depok\, Indonesia +END:VEVENT +END:VCALENDAR \ No newline at end of file From d2395dadfb9e9e7f7271e19575f4e4fb5f47cdf3 Mon Sep 17 00:00:00 2001 From: Made Indra <42365530+madeindra@users.noreply.github.com> Date: Sun, 15 Oct 2023 16:08:40 +0700 Subject: [PATCH 2/3] feat: allow ics attachment --- backend/main.go | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/backend/main.go b/backend/main.go index 723ccbd..647a56e 100644 --- a/backend/main.go +++ b/backend/main.go @@ -304,6 +304,12 @@ func App() *cli.App { Usage: "Path to HTML body file", Required: true, }, + &cli.StringFlag{ + Name: "ics-body", + Value: "", + Usage: "Path to ICS body file", + Required: true, + }, &cli.StringFlag{ Name: "recipients", Value: "", @@ -316,8 +322,8 @@ func App() *cli.App { Required: false, }, }, - Usage: "blast-email [subject] [template-plaintext] [template-html-body] [csv-file list destination of emails]", - ArgsUsage: "[subject] [template-plaintext] [template-html-body] [path-csv-file]", + Usage: "blast-email [subject] [template-plaintext] [template-html-body] [attachment-ics-body] [csv-file list destination of emails]", + ArgsUsage: "[subject] [template-plaintext] [template-html-body] [attachment-ics-body] [path-csv-file]", Action: func(cCtx *cli.Context) error { config, err := GetConfig(cCtx.String("config-file-path")) if err != nil { @@ -349,6 +355,7 @@ func App() *cli.App { htmlBody := cCtx.String("html-body") mailCsv := cCtx.String("recipients") singleRecipient := cCtx.String("single-recipient") + icsBody := cCtx.String("ics-body") if subject == "" { log.Fatal().Msg("Subject is required") @@ -377,14 +384,14 @@ func App() *cli.App { if err != nil { log.Fatal().Err(err).Msg("failed to read html template") } - + htmlTemplate, err := handlebars.Parse(string(htmlContent)) if err != nil { log.Fatal().Err(err).Msg("failed to parse html template") } - + var userList []User - + if mailCsv != "" { emailList, err := os.ReadFile(mailCsv) if err != nil { @@ -400,6 +407,14 @@ func App() *cli.App { Email: singleRecipient, }) } + + var icsContent []byte + if icsBody != "" { + icsContent, err = os.ReadFile(icsBody) + if err != nil { + log.Fatal().Err(err).Msg("failed to read ics attachment") + } + } mailSender := NewMailSender(&MailConfiguration{ SmtpHostname: config.Mailer.Hostname, @@ -408,6 +423,17 @@ func App() *cli.App { SmtpPassword: config.Mailer.Password, }) + attachments := []Attachment{} + if (icsContent != nil){ + attachments := append(attachments, Attachment{ + ContentDisposition: ContentDispositionAttachment, + Name: "invite.ics", + Description: "Invitation", + ContentType: "application/ics", + Payload: icsBody, + }) + } + for _, user := range userList { mail := &Mail{ RecipientName: user.Name, @@ -415,6 +441,7 @@ func App() *cli.App { Subject: subject, PlainTextBody: string(plaintextContent), HtmlBody: string(htmlContent), + Attachments } // Parse email template information From 1fe344992cc1c22565d28cac89775f287795e563 Mon Sep 17 00:00:00 2001 From: Indra Made Date: Sun, 15 Oct 2023 16:24:35 +0700 Subject: [PATCH 3/3] fix: add missing field --- backend/main.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/backend/main.go b/backend/main.go index 647a56e..42b6beb 100644 --- a/backend/main.go +++ b/backend/main.go @@ -384,14 +384,14 @@ func App() *cli.App { if err != nil { log.Fatal().Err(err).Msg("failed to read html template") } - + htmlTemplate, err := handlebars.Parse(string(htmlContent)) if err != nil { log.Fatal().Err(err).Msg("failed to parse html template") } - + var userList []User - + if mailCsv != "" { emailList, err := os.ReadFile(mailCsv) if err != nil { @@ -407,7 +407,7 @@ func App() *cli.App { Email: singleRecipient, }) } - + var icsContent []byte if icsBody != "" { icsContent, err = os.ReadFile(icsBody) @@ -424,13 +424,13 @@ func App() *cli.App { }) attachments := []Attachment{} - if (icsContent != nil){ - attachments := append(attachments, Attachment{ + if icsContent != nil { + attachments = append(attachments, Attachment{ ContentDisposition: ContentDispositionAttachment, - Name: "invite.ics", - Description: "Invitation", - ContentType: "application/ics", - Payload: icsBody, + Name: "invite.ics", + Description: "Invitation", + ContentType: "application/ics", + Payload: icsContent, }) } @@ -441,7 +441,7 @@ func App() *cli.App { Subject: subject, PlainTextBody: string(plaintextContent), HtmlBody: string(htmlContent), - Attachments + Attachments: attachments, } // Parse email template information