Skip to content

Commit

Permalink
Merge pull request #153 from yashlm/updating-emails
Browse files Browse the repository at this point in the history
Updating mail template
  • Loading branch information
yashlm authored Jun 19, 2024
2 parents 448821b + 3220090 commit dc351f4
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 12 deletions.
40 changes: 28 additions & 12 deletions mail/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/smtp"
"strings"
"time"

"text/template"
"github.com/sirupsen/logrus"
)

Expand All @@ -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", "<br>", -1)
message += "<br><br>--<br>Recruitment Automation System<br>"
message += "Indian Institute of Technology Kanpur<br><br>"
message += "<small>This is an auto-generated email. Please do not reply.</small>"
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 {
Expand Down Expand Up @@ -66,4 +82,4 @@ func Service(mailQueue chan Mail) {
time.Sleep(1 * time.Second)
}
}
}
}
151 changes: 151 additions & 0 deletions mail/templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package mail

const (
DefaultTemplate = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<html dir="ltr" lang="en">
<head></head>
<body style="background-color:#ffffff;margin:0 auto;font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif">
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="max-width:37.5em;margin:0 auto;padding:0px 20px">
<tbody>
<tr style="width:100%">
<td>
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-top:10px">
<tbody>
<tr>
<td><img alt="Recruitment Automation System &lt;br /&gt; Indian Institute of Technology, Kanpur" height="75" src="https://i.ibb.co/h7HMySr/Screenshot-from-2024-04-06-07-02-51.png" style="display:block;outline:none;border:none;text-decoration:none" width="475" /></td>
</tr>
</tbody>
</table>
<h1 style="color:#1d1c1d;font-size:36px;font-weight:700;margin:30px 0;padding:0;line-height:42px">{{.Subject}}</h1>
<p style="font-size:24px;line-height:28px;margin:16px 0;margin-bottom:30px">{{.Body}}<br></br></p>
<p style="font-size:16px;line-height:24px;margin:16px 0;color:#000">This is an auto-generated email. Please do not reply.</p>
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation">
<tbody>
<tr>
<td>
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-bottom:32px;padding-left:8px;padding-right:8px;width:100%">
<tbody style="width:100%">
<tr style="width:100%">
<td data-id="__react-email-column" style="width:66%"><img alt="IIT Kanpur" height="48" src="https://upload.wikimedia.org/wikipedia/en/thumb/a/a3/IIT_Kanpur_Logo.svg/1200px-IIT_Kanpur_Logo.svg.png" style="display:block;outline:none;border:none;text-decoration:none" width="48" /></td>
<td data-id="__react-email-column">
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation">
<tbody>
<tr>
<td>
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation">
<tbody style="width:100%">
<tr style="width:100%">
<td data-id="__react-email-column"><a href="https://twitter.com/IITKanpur" style="color:#067df7;text-decoration:none" target="_blank"><img alt="Twitter" height="32" src="https://th.bing.com/th/id/OIP.YGJYM4pqXxVMHzPYfdLumgHaHa?rs=1&amp;pid=ImgDetMain" style="display:inline;outline:none;border:none;text-decoration:none;margin-left:32px" width="32" /></a></td>
<td data-id="__react-email-column"><a href="https://www.facebook.com/spo.iitkanpur/" style="color:#067df7;text-decoration:none" target="_blank"><img alt="Facebook" height="32" src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/2021_Facebook_icon.svg/2048px-2021_Facebook_icon.svg.png" style="display:inline;outline:none;border:none;text-decoration:none;margin-left:32px" width="32" /></a></td>
<td data-id="__react-email-column"><a href="https://www.linkedin.com/company/students-placement-office-iit-kanpur/" style="color:#067df7;text-decoration:none" target="_blank"><img alt="LinkedIn" height="32" src="https://static-00.iconduck.com/assets.00/linkedin-icon-1024x1024-net2o24e.png" style="display:inline;outline:none;border:none;text-decoration:none;margin-left:32px" width="32" /></a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation">
<tbody>
<tr>
<td><a href="https://spo.iitk.ac.in/" rel="noopener noreferrer" style="color:#b7b7b7;text-decoration:underline" target="_blank">Website</a> | <a href="https://placement.iitk.ac.in/" rel="noopener noreferrer" style="color:#b7b7b7;text-decoration:underline" target="_blank">RAS Portal</a> | <a href="https://phdplacement.iitk.ac.in/" rel="noopener noreferrer" style="color:#b7b7b7;text-decoration:underline" target="_blank">PhD Portal</a>
<p style="font-size:12px;line-height:15px;margin:16px 0;color:#b7b7b7;text-align:left;margin-bottom:50px">©2024 Recruitment Automation System. <br />Students&#x27; Placement Office, IIT Kanpur <br /><br />All rights reserved.</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>`

// OTPTemplate and RecruitedTemplate are incomplete.

OTPTemplate = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<html dir="ltr" lang="en">
<!-- OTP email template content -->
</html>`

RecruitedTemplate = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<html dir="ltr" lang="en">
<head></head>
<body style="background-color:#ffffff;margin:0 auto;font-family:-apple-system, BlinkMacSystemFont, &#x27;Segoe UI&#x27;, &#x27;Roboto&#x27;, &#x27;Oxygen&#x27;, &#x27;Ubuntu&#x27;, &#x27;Cantarell&#x27;, &#x27;Fira Sans&#x27;, &#x27;Droid Sans&#x27;, &#x27;Helvetica Neue&#x27;, sans-serif">
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="max-width:37.5em;margin:0 auto;padding:0px 20px">
<tbody>
<tr style="width:100%">
<td>
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-top:10px">
<tbody>
<tr>
<td><img alt="Recruitment Automation System &lt;br /&gt; Indian Institute of Technology, Kanpur" height="75" src="https://i.ibb.co/YDvnbf5/Screenshot-2024-02-13-000009.png" style="display:block;outline:none;border:none;text-decoration:none" width="475" /></td>
</tr>
</tbody>
</table>
<h1 style="color:#1d1c1d;font-size:36px;font-weight:700;margin:30px 0;padding:0;line-height:42px">Congratualtions!</h1>
<p style="font-size:24px;line-height:28px;margin:16px 0;margin-bottom:30px">You have been recruited for the position of Software Developer at SPO IITK.<br /></p><img alt="IIT Kanpur" height="300" src="https://i.pinimg.com/originals/ee/cc/42/eecc42c92afa81900f655d4328d790c1.gif" style="display:block;outline:none;border:none;text-decoration:none" width="600" />
<p style="font-size:18px;line-height:24px;margin:16px 0;color:#000">This is an auto-generated email. Please do not reply.</p>
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation">
<tbody>
<tr>
<td>
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-bottom:32px;padding-left:8px;padding-right:8px;width:100%">
<tbody style="width:100%">
<tr style="width:100%">
<td data-id="__react-email-column" style="width:66%"><img alt="IIT Kanpur" height="48" src="https://upload.wikimedia.org/wikipedia/en/thumb/a/a3/IIT_Kanpur_Logo.svg/1200px-IIT_Kanpur_Logo.svg.png" style="display:block;outline:none;border:none;text-decoration:none" width="48" /></td>
<td data-id="__react-email-column">
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation">
<tbody>
<tr>
<td>
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation">
<tbody style="width:100%">
<tr style="width:100%">
<td data-id="__react-email-column"><a href="https://twitter.com/IITKanpur" style="color:#067df7;text-decoration:none" target="_blank"><img alt="Twitter" height="32" src="https://th.bing.com/th/id/OIP.YGJYM4pqXxVMHzPYfdLumgHaHa?rs=1&amp;pid=ImgDetMain" style="display:inline;outline:none;border:none;text-decoration:none;margin-left:32px" width="32" /></a></td>
<td data-id="__react-email-column"><a href="https://www.facebook.com/spo.iitkanpur/" style="color:#067df7;text-decoration:none" target="_blank"><img alt="Facebook" height="32" src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/2021_Facebook_icon.svg/2048px-2021_Facebook_icon.svg.png" style="display:inline;outline:none;border:none;text-decoration:none;margin-left:32px" width="32" /></a></td>
<td data-id="__react-email-column"><a href="https://www.linkedin.com/company/students-placement-office-iit-kanpur/" style="color:#067df7;text-decoration:none" target="_blank"><img alt="LinkedIn" height="32" src="https://static-00.iconduck.com/assets.00/linkedin-icon-1024x1024-net2o24e.png" style="display:inline;outline:none;border:none;text-decoration:none;margin-left:32px" width="32" /></a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation">
<tbody>
<tr>
<td><a href="https://spo.iitk.ac.in/" rel="noopener noreferrer" style="color:#b7b7b7;text-decoration:underline" target="_blank">Website</a> | <a href="https://placement.iitk.ac.in/" rel="noopener noreferrer" style="color:#b7b7b7;text-decoration:underline" target="_blank">RAS Portal</a> | <a href="https://phdplacement.iitk.ac.in/" rel="noopener noreferrer" style="color:#b7b7b7;text-decoration:underline" target="_blank">PhD Portal</a>
<p style="font-size:12px;line-height:15px;margin:16px 0;color:#b7b7b7;text-align:left;margin-bottom:50px">©2024 Recruitment Automation System. <br />Students&#x27; Placement Office, IIT Kanpur <br /><br />All rights reserved.</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>`
)

0 comments on commit dc351f4

Please sign in to comment.