This project is a Go application that sends emails using HTML templates with inheritance. It supports sending emails with attachments and plain text versions of the HTML content. The email templates are styled using Google Fonts and include a header, footer, and disclaimer.
- Send emails with HTML content
- Template inheritance for reusable HTML structures
- Send plain text versions of the emails
- Attach files to emails
- Use environment variables for configuration
- Go 1.16+
- SMTP server credentials
- Environment variables setup
git clone https://github.com/Nneji123/golang-html-email.git
git clone https://github.com/MoksDa3rd/golang-html-email.git
cd golang-html-email
go get -u github.com/jordan-wright/email
go get -u github.com/joho/godotenv
Create a .env
file in the root of your project and add your SMTP server credentials:
EMAIL_HOST=smtp.your-email-provider.com
EMAIL_HOST_USER=your-email@example.com
EMAIL_HOST_PASSWORD=your-email-password
Create two HTML template files, base.html
and content.html
, in the same directory as the Go program. These templates will define the structure and content of your emails.
- Make sure you have the necessary environment variables set up in the
.env
file. - Ensure your HTML templates (
base.html
andcontent.html
) and any attachment files are in the same directory as the Go program. - Run the program:
go run main.go
The main.go
file includes an example usage of the SendEmail
function. Modify the example to suit your needs, including setting the email subject, recipients, context variables, and attachments.
.
├── .env
├── base.html
├── content.html
├── main.go
├── sample.pdf
.env
: Environment variables file containing SMTP server credentials.base.html
: Base HTML template with common email structure.content.html
: HTML template extending the base template with specific email content.main.go
: Go program file containing theSendEmail
function and example usage.sample.pdf
: Example attachment file.
This project is licensed under the MIT License. See the LICENSE file for details.