O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The smtp package provides the basic functionality to interact with the SMTP server. The Dial function provides the client. The most significant methods of the client are Mail, which sets the sender mail, Rcpt, which sets the recipients mail, and Data, which provides the Writer, where the content of the mail can be written. Finally, the Quit method sends QUIT and closes the connection to the server.

The previous example uses a secured connection to the SMTP server so the Auth method of the client is utilized to set the authentication, and the StartTLS method is called to start a secured connection to the server.

Note that the Auth structure is created separately with the PlainAuth function of the smtp package.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required