mattjackson220 commented on a change in pull request #3534: TP Delivery Service
Generate SSL update, new letsencrypt generate and…
URL: https://github.com/apache/trafficcontrol/pull/3534#discussion_r336005566
##########
File path: traffic_ops/traffic_ops_golang/api/api.go
##########
@@ -786,3 +792,81 @@ func AddUserToReq(r *http.Request, u auth.CurrentUser) {
ctx = context.WithValue(ctx, auth.CurrentUserKey, u)
*r = *r.WithContext(ctx)
}
+
+func SendEmail(config config.Config, header string, data interface{},
templateFile string, toEmail string) error {
+ email := rfc.EmailAddress{
+ Address: mail.Address{Name: "", Address: toEmail},
+ }
+
+ msgBodyBuffer, err := parseTemplate(templateFile, data)
+ if err != nil {
+ return err
+ }
+ msg := append([]byte(header), msgBodyBuffer.Bytes()...)
+
+ int, userError, systemError := SendMail(email, msg, &config)
+ if userError != nil {
+ return errors.New("Failed to send email: " + userError.Error())
+ }
+ if systemError != nil {
+ return errors.New("Failed to send email: " + userError.Error())
+ }
+ if int != http.StatusOK {
+ return errors.New("Failed to send email. Unexpected response
code: " + strconv.Itoa(int))
+ }
+ return nil
+}
+
+func parseTemplate(templateFileName string, data interface{}) (*bytes.Buffer,
error) {
+ t, err := template.ParseFiles(templateFileName)
+ if err != nil {
+ return nil, err
+ }
+ buf := new(bytes.Buffer)
+ if err = t.Execute(buf, data); err != nil {
+ return nil, err
+ }
+ return buf, nil
+}
+
+type loginAuth struct {
+ identity, username, password string
+ host string
Review comment:
done. yea it was ok with it but i changed them all to be on the same now
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services