diff --git a/backend/main.go b/backend/main.go index 723ccbd..42b6beb 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") @@ -401,6 +408,14 @@ func App() *cli.App { }) } + 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, SmtpPort: config.Mailer.Port, @@ -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: icsContent, + }) + } + 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: attachments, } // Parse email template information 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