Sending emails through Sendgrid or GMail API
go build -o <output_file> .\main.go
- Update
configs/message.json
.
{
"from": "Mail send from",
"email": "xxx@domain.com"
"subject": "This my first mail",
"content": "Test mail"
}
- Update
configs/maillist.csv
, the file listed email address to be sent.
<Name>,<Email>,<Attachment>
WILL HUANG,a12345@gmail.com,TEST.pdf
WILL WEI,a2345@gmail.com,TEST2.txt
-
Setup a Sendgrid account and create the API key. link
-
Update
configs/config.json
- Update
sendgridApiKey
to the created one from first step.
- Update
-
Execute and EMail sent
[SUCCESS] sending mail to: WILL HUANG a12345@gmail.com
[SUCCESS] sending mail to: WILL WEI a2345@gmail.com
-
Google API Setup:
-
Update
configs/config.json
- Update "gamilCredentials" to
configs/gmail/credentials.json
.
- Update "gamilCredentials" to
-
First time execute and autorization:
- Execute the program and you will see following statement, follow the link to authorize the application.
Go to the following link in your browser then type the authorization code: https://<Authorization URL>
- Copy the token from browser and enter the token as following.
Please enter the auto code from browser: <COPY FROM Browser>
-
EMail sent
[SUCCESS] sending mail to: WILL HUANG a12345@gmail.com
[SUCCESS] sending mail to: WILL WEI a2345@gmail.com