From b4273d2fbd23a2182b93c10d028e61430a7665ac Mon Sep 17 00:00:00 2001 From: Yash Chauhan Date: Thu, 15 Feb 2024 05:32:19 +0530 Subject: [PATCH 1/2] added DefaultTemplate for email --- mail/service.go | 40 ++++++++---- mail/templates.go | 151 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+), 12 deletions(-) create mode 100644 mail/templates.go diff --git a/mail/service.go b/mail/service.go index 6a7e629..7cc444b 100644 --- a/mail/service.go +++ b/mail/service.go @@ -5,7 +5,7 @@ import ( "net/smtp" "strings" "time" - + "text/template" "github.com/sirupsen/logrus" ) @@ -16,23 +16,39 @@ type Mail struct { } func (mail *Mail) BuildMessage() []byte { - message := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\r\n" - message += fmt.Sprintf("From: Recruitment Automation System IITK<%s>\r\n", sender) - message += fmt.Sprintf("Subject: %s | Recruitment Automation System\r\n", mail.Subject) + + type TemplateData struct { + To []string + Subject string + Body string + } + + var message strings.Builder + + msg := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\r\n" + msg += fmt.Sprintf("From: Recruitment Automation System IITK<%s>\r\n", sender) + msg += fmt.Sprintf("Subject: %s\r\n", mail.Subject) // If mass mailing, BCC all the users if len(mail.To) == 1 { - message += fmt.Sprintf("To: %s\r\n\r\n", mail.To[0]) + msg += fmt.Sprintf("To: %s\r\n\r\n", mail.To[0]) } else { - message += fmt.Sprintf("To: Undisclosed Recipients<%s>\r\n\r\n", webteam) + msg += fmt.Sprintf("To: Undisclosed Recipients<%s>\r\n\r\n", webteam) } - message += strings.Replace(mail.Body, "\n", "
", -1) - message += "

--
Recruitment Automation System
" - message += "Indian Institute of Technology Kanpur

" - message += "This is an auto-generated email. Please do not reply." + message.WriteString(msg) + + tmpl := template.Must(template.New("Template").Parse(DefaultTemplate)) + err := tmpl.Execute(&message, TemplateData{ + Subject: mail.Subject, + Body: mail.Body, + }) + if err != nil { + logrus.Errorf("Error executing email template: %v", err) + return nil + } - return []byte(message) + return []byte(message.String()) } func batchEmails(to []string, batch int) [][]string { @@ -66,4 +82,4 @@ func Service(mailQueue chan Mail) { time.Sleep(1 * time.Second) } } -} +} \ No newline at end of file diff --git a/mail/templates.go b/mail/templates.go new file mode 100644 index 0000000..a5b49ef --- /dev/null +++ b/mail/templates.go @@ -0,0 +1,151 @@ +package mail + +const ( + DefaultTemplate = ` + + + + + + + + + + +
+ + + + + + +
Recruitment Automation System <br /> Indian Institute of Technology, Kanpur
+

{{.Subject}}

+

{{.Body}}

+

This is an auto-generated email. Please do not reply.

+ + + + + + +
+ + + + + + + +
IIT Kanpur + + + + + + +
+ + + + + + + + +
TwitterFacebookLinkedIn
+
+
+
+ + + + + + +
Website | RAS Portal | PhD Portal +

©2024 Recruitment Automation System.
Students' Placement Office, IIT Kanpur

All rights reserved.

+
+
+ + ` + + // OTPTemplate and RecruitedTemplate are incomplete. + + OTPTemplate = ` + + + +` + + RecruitedTemplate = ` + + + + + + + + + + + + +
+ + + + + + +
Recruitment Automation System <br /> Indian Institute of Technology, Kanpur
+

Congratualtions!

+

You have been recruited for the position of Software Developer at SPO IITK.

IIT Kanpur +

This is an auto-generated email. Please do not reply.

+ + + + + + +
+ + + + + + + +
IIT Kanpur + + + + + + +
+ + + + + + + + +
TwitterFacebookLinkedIn
+
+
+
+ + + + + + +
Website | RAS Portal | PhD Portal +

©2024 Recruitment Automation System.
Students' Placement Office, IIT Kanpur

All rights reserved.

+
+
+ + ` +) \ No newline at end of file From 3220090c1e7a0e01662552067d880c50977505ed Mon Sep 17 00:00:00 2001 From: Yash Chauhan Date: Sat, 6 Apr 2024 07:35:46 +0530 Subject: [PATCH 2/2] image link changed --- mail/templates.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mail/templates.go b/mail/templates.go index a5b49ef..f282a70 100644 --- a/mail/templates.go +++ b/mail/templates.go @@ -13,7 +13,7 @@ const ( - +
Recruitment Automation System <br /> Indian Institute of Technology, KanpurRecruitment Automation System <br /> Indian Institute of Technology, Kanpur