envio de email via SMTP com anexo usando Go

gosendmail - SMTP

This repo is a simple net/smtp abstraction for sending emails using SMTP. With it we can send emails With copy, with blind copy and attachments. The body is plain text, we're still going to make a version to accept HTML, at the moment only text/plain in the Body. The attachment must pass the complete path so that the package can open the file. There are 4 environment variables to be configured, they are:

- EMAIL_HOST
- EMAIL_USERNAME
- EMAIL_PASSWORD
- EMAIL_PORT

Below is an example of how you might use pkg.

package main

import gse "github.com/jotonilima/gosendmail"
import "log" 


func main() {
 	email := gse.New()
 	if email == nil {
 		log.Println("Error New() check the required fields: 
		 EMAIL_HOST,EMAiL_USERNAME,EMAIL_PASSWORD,EMAIL_PORT")
 		return
 	}
 	m := gse.NewMessage("Title here", "Body message here.")
 	m.To = []string{"<to-email>@gmail.com"}
 	m.CC = []string{"<copy1-email>@gmail.com", "<copy2-email>@gmail.com"}
 	m.BCC = []string{"<bc-email>@gmail.com"}
 	m.AttachFile("/path/to/file1.pdf")
 	m.AttachFile("/path/to/file2.pdf")
 	if email.Send(m) != nil {
 		log.Println("Error when sending:", err.Error())
 		return
 	}
 	log.Println("Sent with success")
}

To run the code above:

$ export EMAIL_HOST="smtp.<YOUR-SERVER>.com"
$ export EMAIL_USERNAME="<USER>"
$ export EMAIL_PASSWORD="<PASSWORD>"
$ export EMAIL_PORT="587"
$ go mod init <your-pkg>
$ go mod tidy
$ go run main
Owner
Jefferson Otoni Lima
Senior Software Enginer and Architect entrepreneur since 2006, currently as Senior Software Enginer at Engineering Brasil and CEO & Co-Fundador S3WF
Jefferson Otoni Lima
Similar Resources

golang honeypot smtp server

golang honeypot smtp server

honeygogo-smtp standalone honeypot A lightweight SMTP honeypot server written in Go, leveraging go-smtp. A stand alone version of a module from honeyg

May 4, 2022

Simple SMTP Server for Testing

go-smtptester Simple SMTP Server for Testing. How it works All received mails are saved in a sync.Map with a key: From+Recipient1+Recipient2 Mails to

Nov 18, 2021

Simple tool to test SMTP mail send with various settings including TLS1.1 downgrade

smtptest Simple tool to test SMTP mail send with various settings including TLS1.1 downgrade All settings are configurable in the config.yaml file ser

Sep 19, 2022

Robust and flexible email library for Go

email Robust and flexible email library for Go Email for humans The email package is designed to be simple to use, but flexible enough so as not to be

Dec 30, 2022

:white_check_mark: A Go library for email verification without sending any emails.

email-verifier ✉️ A Go library for email verification without sending any emails. Features Email Address Validation: validates if a string contains a

Dec 30, 2022

An email MIME artist for golang

Marcel is a tool to generate IETF compliant emails in raw MIME format. I mainly use this for generating emails with attachments and sending them via amazon SES. If that's what you're doing too, you may want notifications

Nov 7, 2022

EMail Searcher By Golang

EMail Searcher By Golang

GiveMeMail ▄████ ██▓ ██▒ ██▓ ▓██████ ███▄ ▄███▓▓██████ ███▄ ▄███▓ ██ ██▓ ██▓ ██▒ ▀█▒ ▓██▒ ▓██░ █▒ ▓█ ▀ ▓██▒▀█▀ ██▒▓█

Dec 4, 2021

✉️ A Go library for email verification without sending any emails.

email-verifier ✉️ A Go library for email verification without sending any emails. Features Email Address Validation: validates if a string contains a

Jun 24, 2021

End-to-end encrypted email for the mesh networking age

Yggmail It's email, but not as you know it. Introduction Yggmail is a single-binary all-in-one mail transfer agent which sends and receives email nati

Jan 2, 2023
Related tags
:incoming_envelope: Simple email interface across multiple service providers (ses, postmark, mandrill, smtp)
:incoming_envelope: Simple email interface across multiple service providers (ses, postmark, mandrill, smtp)

go-mail Lightweight email package with multi-provider support (ses, mandrill, postmark) Table of Contents Installation Documentation Examples & Tests

Dec 10, 2022
Pretty wrapper for sending email using go net/smtp

Emailer A pretty wrapper around go net/smtp send multiple email using single client func main() { var client *emailer.Client var clientX sync.Mute

Mar 23, 2022
VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients
VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients

VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients Email clients use different rendering standards. This is

Dec 17, 2022
Email-searcher - Given a domain name and real name, attempt to find an existing email for that user.

email-searcher Given a domain name and real name, attempt to find an existing email for that user. Using Run it with both the domain and name flags, l

Jan 2, 2022
Sending emails using email server talking to RabbitMQ and send grid server sending emails to email ids consumed from RabbitMQ
Sending emails using email server talking to RabbitMQ and send grid server sending emails to email ids consumed from RabbitMQ

Sending emails using email server talking to RabbitMQ and send grid server sending emails to email ids consumed from RabbitMQ

Oct 27, 2022
a simple api that sent spam via sms and email

a simple api that sent spam via sms and email routes: /sms /email example request with python

Oct 19, 2021
Lightweight SMTP client written in Go

Hectane Hectane is both a Go package providing an SMTP queue for sending emails and a standalone application that exposes this functionality via an HT

Nov 23, 2022
Web and API based SMTP testing
Web and API based SMTP testing

MailHog Inspired by MailCatcher, easier to install. Download and run MailHog Configure your outgoing SMTP server View your outgoing email in a web UI

Jan 4, 2023
MailHog SMTP Protocol

MailHog SMTP Protocol github.com/mailhog/smtp implements an SMTP server state machine. It attempts to encapsulate as much of the SMTP protocol (plus i

Oct 27, 2022
Disposable webmail server (similar to Mailinator) with built in SMTP, POP3, RESTful servers; no DB required.
Disposable webmail server (similar to Mailinator) with built in SMTP, POP3, RESTful servers; no DB required.

Disposable webmail server (similar to Mailinator) with built in SMTP, POP3, RESTful servers; no DB required.

Jan 1, 2023