Advertisement
Guest User

Untitled

a guest
Jun 7th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. 2016/06/07 10:27:03 534 5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbtq
  2. 5.7.14 ZHRyO8gjNXDZjjls6t7JWkP7y1UM8Jc44oPvw0dXO96SljvNT3d2QDMlJAT3X7p4teLYY1
  3. 5.7.14 zj9NBwLOytlrdRXkjm7BZNWpPLLscyxEOUcyLL3EFHdnYiq_1P_PwQVcLvZlVGUdChm_
  4. 5.7.14 6BIdD9uJLkOOG_6b6oXyJ1YfZJneoM8IiUYlWaecNECJQYF8WLYY3hSCCnNDazjJuRvjbH
  5. 5.7.14 yqJu4xBfx-929yDQwvPmuVxL4bQv8> Please log in via your web browser and
  6. 5.7.14 then try again.
  7. 5.7.14 Learn more at
  8. 5.7.14 https://support.google.com/mail/answer/78754 89sm7243327qth.2 - gsmtp
  9.  
  10. type Mail struct {
  11. Hostname string
  12. Port string
  13. User string
  14. Password string
  15. Header map[string]string
  16. IsHTML bool
  17. Subject string
  18. Body string
  19. Recipients []string
  20. }
  21.  
  22. func New() *Mail {
  23. return &Mail{
  24. Hostname: cfg.MailHost,
  25. Port: cfg.MailPort,
  26. User: cfg.MailUser,
  27. Password: cfg.MailPass,
  28. Header: map[string]string{},
  29. IsHTML: true,
  30. }
  31. }
  32.  
  33. func (m *Mail) AddHeader(key, value string) {
  34. m.Header[key] = value
  35. }
  36.  
  37. func (m *Mail) AddRecipient(address string) {
  38. m.Recipients = append(m.Recipients, address)
  39. m.AddHeader("To", "<"+address+">")
  40. }
  41.  
  42. func (m *Mail) HTML(isHTML bool) {
  43. m.IsHTML = isHTML
  44. }
  45.  
  46. func (m *Mail) Send() error {
  47.  
  48. if m.Subject == "" {
  49. m.Subject = "Some random subject..."
  50. }
  51. m.AddHeader("Subject", m.Subject)
  52.  
  53. if _, ok := m.Header["From"]; !ok {
  54. m.AddHeader("From", cfg.MailName+" <"+cfg.MailUser+">")
  55. }
  56.  
  57. if m.IsHTML {
  58. m.AddHeader("MIME-version", "1.0;")
  59. m.AddHeader("Content-Type", "text/html; charset="UTF-8";")
  60. }
  61.  
  62. body := ""
  63. for k, v := range m.Header {
  64. body += fmt.Sprintf("%s: %srn", k, v)
  65. }
  66. body += "rn" + m.Body
  67.  
  68. auth := smtp.PlainAuth("", m.User, m.Password, m.Hostname)
  69.  
  70. err := smtp.SendMail(
  71. m.Hostname+":"+m.Port,
  72. auth,
  73. m.User,
  74. m.Recipients,
  75. []byte(body),
  76. )
  77.  
  78. if err != nil {
  79. return err
  80. }
  81. return nil
  82. }
  83.  
  84. MailHost = "smtp.gmail.com"
  85. MailPort = "587"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement