"use strict";(self.webpackChunkgoffee_site=self.webpackChunkgoffee_site||[]).push([[9222],{8057:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>o,default:()=>m,frontMatter:()=>r,metadata:()=>a,toc:()=>l});var s=t(4848),i=t(8453);const r={title:"Sending Emails"},o=void 0,a={id:"emails",title:"Sending Emails",description:"Goffee supports 3 different drivers for sending emails, SMTP, SparkPost, SendGrid, and MailGun.",source:"@site/docs/emails.md",sourceDirName:".",slug:"/emails",permalink:"/goffee/docs/emails",draft:!1,unlisted:!1,tags:[],version:"current",frontMatter:{title:"Sending Emails"},sidebar:"docsSidebar",previous:{title:"Hashing passowrds",permalink:"/goffee/docs/hashing"},next:{title:"Events",permalink:"/goffee/docs/events"}},d={},l=[{value:"Emails drivers config",id:"emails-drivers-config",level:3},{value:"Sending emails",id:"sending-emails",level:3}];function c(e){const n={code:"code",h3:"h3",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["Goffee supports 3 different drivers for sending emails, ",(0,s.jsx)(n.code,{children:"SMTP"}),", ",(0,s.jsx)(n.code,{children:"SparkPost"}),", ",(0,s.jsx)(n.code,{children:"SendGrid"}),", and ",(0,s.jsx)(n.code,{children:"MailGun"}),".\nThe driver can be selected by setting the value of the variable ",(0,s.jsx)(n.code,{children:"EMAILS_DRIVER"})," to either ",(0,s.jsx)(n.code,{children:"smtp"}),", ",(0,s.jsx)(n.code,{children:"sparkpost"}),", ",(0,s.jsx)(n.code,{children:"sendgrid"}),", or ",(0,s.jsx)(n.code,{children:"mailgun"}),"\neach driver has it's own configuration variables, they can be defined either in the ",(0,s.jsx)(n.code,{children:".env"})," file or can be injected into the environemnt using an external tool."]}),"\n",(0,s.jsx)(n.h3,{id:"emails-drivers-config",children:"Emails drivers config"}),"\n",(0,s.jsx)(n.p,{children:"Here is an example for the emails config"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"#######################################\n######           Emails          ######\n#######################################\nEMAILS_DRIVER=smtp # smtp | sparkpost | sendgrid | mailgun\n#_____ SMTP _____#\nSMTP_HOST=localhost\nSMTP_PORT=25\nSMTP_USERNAME=\nSMTP_PASSWORD=\nSMTP_TLS_SKIP_VERIFY_HOST=true # (set true for development only!)\n\n#_____ sparkpost _____#\nSPARKPOST_BASE_URL=https://api.sparkpost.com\nSPARKPOST_API_VERSION=1\nSPARKPOST_API_KEY=sparkpost-api-key-here # the api key\n\n#_____ sendgrid _____#\nSENDGRID_HOST=https://api.sendgrid.com\nSENDGRID_ENDPOINT=/v3/mail/send\nSENDGRID_API_KEY=sendgrid-api-key-here # the api key\n\n#_____ mailgun _____#\nMAILGUN_DOMAIN=your-domain.com # your domain\nMAILGUN_API_KEY=mailgun-api-key-here # the api key\nMAILGUN_TLS_SKIP_VERIFY_HOST=true # (set true for development only!)\n"})}),"\n",(0,s.jsx)(n.h3,{id:"sending-emails",children:"Sending emails"}),"\n",(0,s.jsx)(n.p,{children:"Here is an example for sending an email"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:'package controllers\n\nimport (\n\t"fmt"\n\n\t"git.smarteching.com/goffee/core"\n)\n\nfunc SayHelloWorld(c *core.Context) *core.Response {\n    mailer := c.GetMailer()\n\t// set from\n\tmailer.SetFrom(core.EmailAddress{Name: "jack", Address: "jack@example.com"})\n\t// set to\n\tmailer.SetTo([]core.EmailAddress{{Name: "jane", Address: "jane@example.com"}})\n\t// set cc\n\tmailer.SetCC([]core.EmailAddress{{Name: "john", Address: "john@example.com"}})\n\t// set bcc\n\tmailer.SetBCC([]core.EmailAddress{{Name: "bcc", Address: "bcc@example.com"}})\n\t// set the subject\n\tmailer.SetSubject(`Hello world`)\n\t// set the body\n\tmailer.SetHTMLBody(`<h1>Hello world from email</h1>`)\n\t// set attachment\n\tmailer.SetAttachments([]core.EmailAttachment{{\n        Name: "my first file", \n        Path: "./storage/my-first-file.pdf"\n    }})\n\t// send\n\tmailer.Send()\n}\n'})})]})}function m(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>o,x:()=>a});var s=t(6540);const i={},r=s.createContext(i);function o(e){const n=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:n},e.children)}}}]);