Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): allow ics invitation #78

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -401,20 +408,40 @@ 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,
SmtpFrom: config.Mailer.From,
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,
RecipientEmail: user.Email,
Subject: subject,
PlainTextBody: string(plaintextContent),
HtmlBody: string(htmlContent),
Attachments: attachments,
}

// Parse email template information
Expand Down
26 changes: 26 additions & 0 deletions emails/payment_success.ics
Original file line number Diff line number Diff line change
@@ -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:[email protected]
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