-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6dd970
commit d7d7fcd
Showing
18 changed files
with
274 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,3 +85,10 @@ name = "shig" | |
[web] | ||
enable = true | ||
dir = "./web" | ||
|
||
[mail] | ||
enable = false | ||
from = "[email protected]" | ||
password = "" | ||
smtpHost = "smtp.gmail.com" | ||
smtpPort = "587" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package mail | ||
|
||
type MailConfig struct { | ||
Enable bool `mapstructure:"enable"` | ||
From string `mapstructure:"from"` | ||
Pass string `mapstructure:"password"` | ||
SmtpHost string `mapstructure:"smtpHost"` | ||
SmtpPort string `mapstructure:"smtpPort"` | ||
} | ||
|
||
func ValidateEmailConfig(config *MailConfig) error { | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,53 +5,59 @@ import ( | |
"fmt" | ||
"html/template" | ||
"net/smtp" | ||
"net/url" | ||
) | ||
|
||
type SenderService struct { | ||
cfg *MailConfig | ||
instanceUrl *url.URL | ||
} | ||
|
||
func NewSenderService() *SenderService { | ||
return &SenderService{} | ||
func NewSenderService(config *MailConfig, instanceUrl *url.URL) *SenderService { | ||
return &SenderService{ | ||
cfg: config, | ||
instanceUrl: instanceUrl, | ||
} | ||
} | ||
|
||
func (s *SenderService) SendRegisterMail(name string, email string, activateToken string) { | ||
|
||
// Sender data. | ||
from := "[email protected]" | ||
password := "Faderef661$##" | ||
func (s *SenderService) SendActivateAccountMail(name string, email string, activateToken string) error { | ||
|
||
// Receiver email address. | ||
to := []string{ | ||
"[email protected]", | ||
if !s.cfg.Enable { | ||
return nil | ||
} | ||
|
||
// smtp server configuration. | ||
smtpHost := "smtp.gmail.com" | ||
smtpPort := "587" | ||
// Receiver email address. | ||
to := []string{email} | ||
link := s.instanceUrl.String() + "/activateAccount/" + activateToken | ||
|
||
// Authentication. | ||
auth := smtp.PlainAuth("", from, password, smtpHost) | ||
auth := smtp.PlainAuth("", s.cfg.From, s.cfg.Pass, s.cfg.SmtpHost) | ||
|
||
t, _ := template.ParseFiles("register.html") | ||
t, err := template.ParseFiles("internal/mail/template/activate_account.html") | ||
if err != nil { | ||
return fmt.Errorf("parsing email template: %w", err) | ||
} | ||
|
||
var body bytes.Buffer | ||
|
||
mimeHeaders := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n" | ||
body.Write([]byte(fmt.Sprintf("Subject: This is a test subject \n%s\n\n", mimeHeaders))) | ||
if _, err = body.Write([]byte(fmt.Sprintf("Subject: Activate Your Account \n%s\n\n", mimeHeaders))); err != nil { | ||
return fmt.Errorf("writing email boddy: %w", err) | ||
} | ||
|
||
t.Execute(&body, struct { | ||
Name string | ||
Message string | ||
User string | ||
Link string | ||
Instance string | ||
}{ | ||
Name: "Puneet Singh", | ||
Message: "This is a test message in a HTML template", | ||
User: name, | ||
Link: link, | ||
Instance: s.instanceUrl.String(), | ||
}) | ||
|
||
// Sending email. | ||
err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, to, body.Bytes()) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
if err = smtp.SendMail(s.cfg.SmtpHost+":"+s.cfg.SmtpPort, auth, s.cfg.From, to, body.Bytes()); err != nil { | ||
return fmt.Errorf("sendingx email boddy: %w", err) | ||
} | ||
fmt.Println("Email Sent!") | ||
return nil | ||
} |
Oops, something went wrong.