Net/mail Package usage in Golang

Source: Internet
Author: User
Tags key string rfc
This is a creation in Article, where the information may have evolved or changed.

The Net/mail package implements the ability to parse mail messages

Most of this package adheres to the syntax specified in RFC 5322, and the notable differences are:

Old format addresses and addresses embedded in remote information are not resolved
Group address is not parsed
All spacers (CFWS syntax elements) are not supported, such as two-line addresses


Function:

Func parseaddresslist (List string) ([]*address, error)//The function resolves the address list represented by the given character form to the standard address lists.
Type address//The struct represents a separate mail address, one address: "Barry Gibbs <bg@example.com>" will become address{name after address parsing: "Barry Gibbs", Address: "Bg@example.com"}.

Type Address struct {        name    //Proper name;        //User@domain}

Func parseaddress (Address string) (*address, error)//Resolves a separate RFC 5322 address, such as: "Barry Gibbs <bg@example.com>"
Func (a *address) string () string//represents the address represented by a as a legitimate RFC 5322 address string. If the Name field contains non-ASCII characters, it is escaped according to RFC 2047.


The type header//header represents the Key-value pair on the head of a mail message.

Type Header map[string][]string

Func (H Header) AddressList (key String) ([]*address, error)//resolves the value (string) corresponding to the keys key as a list of mailbox addresses and returns
Func (H Header) Date () (time. Time, error)//Gets the value of date in the header
The func (H Header) Get (key string) string//returns the first value assigned to the specified key in the Header. If the key has no value, return ""
Type message//represents a parsed mail message

Type Message struct {        header header        Body   io. Reader}

Func readmessage (R io. Reader) (msg *message, err Error)//reads a message from R, resolves the message header field, and the message body can be from r/msg. Read in the body.


Illustrate usage.

Reference: http://golang.org/pkg/net/mail/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.