Documentation
¶
Overview ¶
Package smtp implements the Simple Mail Transfer Protocol as defined in RFC 5321. It also implements the following extensions:
8BITMIME RFC 1652 AUTH RFC 2554 STARTTLS RFC 3207
Additional extensions may be handled by clients.
The smtp package is frozen and is not accepting new features. Some external packages provide more functionality. See:
https://godoc.org/?q=smtp
Index ¶
- Constants
- Variables
- func AdminChecker() gin.HandlerFunc
- func AppMysqlConnector() *gorm.DB
- func AppRedisConnector()
- func AuthChecker() gin.HandlerFunc
- func Case2Camel(name string) string
- func Cmd(command string) string
- func Condition(condition bool, trueVal string, falseVal string) string
- func Cors() gin.HandlerFunc
- func CurlDeleteWithParam(url string, headers map[string]interface{}, params map[string]interface{}) (*goz.Response, error)
- func CurlGet(url string) (*goz.Response, error)
- func CurlGetParam(url string) (*goz.Response, error)
- func CurlPostWithJson(url string, headers map[string]interface{}, params interface{}) (*goz.Response, error)
- func CurlPostWithParam(url string, headers map[string]interface{}, params map[string]interface{}) (*goz.Response, error)
- func CurlPutWithParam(url string, headers map[string]interface{}, params map[string]interface{}) (*goz.Response, error)
- func Decode(decodeStr string) ([]byte, error)
- func Del(key string)
- func Encode(encodeStr string) (string, error)
- func Exist(key string) (int64, error)
- func Expire(key string, exp int)
- func FormatSqlTime(t sql.NullTime) string
- func Get(key string) string
- func GetFirstDateOfMonth(d time.Time) time.Time
- func GetFirstDateOfWeek(d time.Time) time.Time
- func GetLocalIp() string
- func GetLocalMac() string
- func GetRandomString(s int) string
- func InitConfigFromToml() *goconfig.ConfigFile
- func Int64ToString(i int64) string
- func IntToString(i int) string
- func Interface2String(inter interface{}) string
- func JsonMar(data interface{}) []byte
- func JsonUnMar(data []byte) interface{}
- func Lcfirst(str string) string
- func LoadEnv()
- func LoadEnvByCronTask()
- func LogDebug(c *gin.Context, contents ...string)
- func LogError(c *gin.Context, contents ...string)
- func LogInfo(c *gin.Context, contents ...string)
- func LoggerErr(c *gin.Context, err error)
- func PKCS5Padding(ciphertext []byte, blockSize int) []byte
- func PKCS5UnPadding(origData []byte) []byte
- func PanicErr(err error)
- func ParseDays(startDate string, endDate string, dimension string) []string
- func Password(str string) string
- func PathCut(str string, index int) string
- func PrintErr(err error)
- func ProcessDeleteCode(c *gin.Context, resp *goz.Response, result interface{}) map[string]interface{}
- func ProcessGetCode(c *gin.Context, resp *goz.Response, result interface{}) map[string]interface{}
- func ProcessPostCode(c *gin.Context, resp *goz.Response, result interface{}) map[string]interface{}
- func ProcessPutCode(c *gin.Context, resp *goz.Response, result interface{}) map[string]interface{}
- func ReadEnv(filePth string) ([]byte, error)
- func ResultError(key int, data map[string]string) map[string]interface{}
- func ResultSuccess(data map[string]interface{}) map[string]interface{}
- func Run(command string) []byte
- func RunFuncName() string
- func SendByKylin(mail string, subject string, body string)
- func SendMail(addr string, a Auth, from string, to []string, msg []byte) error
- func SendToMail(user, password, host, to, subject, body, mailtype string) error
- func Set(key string, value string, exp int)
- func SetRequestId() gin.HandlerFunc
- func Storage(logType string, content string)
- func StringSliceCut(arr []string, from int, to int) ([]string, error)
- func StringToInt(str string) int
- func StringToInt64(str string) int64
- func StringToIntWithError(str string) (int, error)
- func TZToLocal(utcTime string) string
- func TimeToLocal(utcTime time.Time) string
- func TlsHandler(host string, port string) gin.HandlerFunc
- func ToLocal(utcTime string) string
- func ToUrl(host string, str ...string) string
- func TokenEncode(token UserToken) string
- func UTCTransLocal(utcTime string) string
- func UTCTransLocalEight(utcTime string) string
- func UtcToLocal(utcTime string) string
- func UtcToLocal2(utcTime string) string
- type Auth
- type Client
- func (c *Client) Auth(a Auth) error
- func (c *Client) Close() error
- func (c *Client) Data() (io.WriteCloser, error)
- func (c *Client) Extension(ext string) (bool, string)
- func (c *Client) Hello(localName string) error
- func (c *Client) Mail(from string) error
- func (c *Client) Noop() error
- func (c *Client) Quit() error
- func (c *Client) Rcpt(to string) error
- func (c *Client) Reset() error
- func (c *Client) StartTLS(config *tls.Config) error
- func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool)
- func (c *Client) Verify(addr string) error
- type CodeMsg
- type JsonCamelCase
- type ServerInfo
- type UserToken
- type WSConnection
Constants ¶
const ( USER_NOT_EXIST = 1000 USER_SESSION_CHECK_FAILED = 1001 USER_OR_PASS_ERROR = 1002 TOKEN_MISSING = 1003 TOKEN_VALID = 1004 USER_PASSWORD_ERROR = 1005 ADMIN_AUTH_CHECK_FAILED = 1006 CREATE_USER_FAILED = 1007 PARAMETER_ERROR = 2000 PARAMETER_MISSING = 2001 DB_UPDATE_FAILED = 3000 DB_NOT_EXIST = 3001 FILE_UPLOAD_FAILED = 4000 FILE_DOWNLOAD_FAILED = 4001 GITLAB_SERVICE_FAILED = 5000 GITLAB_SERVICE_UNAUTHORIZED = 5001 GITLAB_AUTHORIZED_MISSING = 5002 GITLAB_MERGE_EXIST = 5003 GITLAB_MERGE_NOTEXIST = 5004 GITLAB_CREATE_FAILED = 5010 GITLAB_DELETE_FAILED = 5011 GITLAB_UPDATE_FAILED = 5012 GITLAB_REQUEST_FAILED = 5013 SONAR_SERVICE_FAILED = 5100 SONAR_SERVICE_UNAUTHORIZED = 5101 SONAR_AUTHORIZED_MISSING = 5102 JENKINS_SERVICE_FAILED = 5200 JENKINS_SERVICE_UNAUTHORIZED = 5201 JENKINS_AUTHORIZED_MISSING = 5202 JENKINS_BUILD_PARAM_ERROR = 5203 JENKINS_BUILD_UNAUTHORIZED = 5204 )
const ( //FROM_EMAIL = "guoliben8@qq.com" //FROM_HOST = "smtp.qq.com" //FROM_PORT = 587 //FROM_ACCOUNT = "guoliben8" //FROM_SECRET = "ehupttnjnbhebhjc" FROM_EMAIL = "guoliben@kylinos.cn" //FROM_HOST = "172.17.111.24" //FROM_HOST = "mailgw.kylinos.cn" FROM_HOST = "172.17.111.24:25" FROM_PORT = 25 FROM_ACCOUNT = "guoliben" FROM_SECRET = "1(T&pi~(4S2" )
const TOKEN_EXP = 10000
Variables ¶
var ClientRedis *redis.Client
var DayTimeFormat = "2006-01-02"
var ForbiddenStr = [256]string{
"su",
"sudo",
"bash",
"sh",
"..",
}
var MonthTimeFormat = "2006-01"
Functions ¶
func AdminChecker ¶
func AdminChecker() gin.HandlerFunc
func AppMysqlConnector ¶
func AppRedisConnector ¶
func AppRedisConnector()
func AuthChecker ¶
func AuthChecker() gin.HandlerFunc
func Case2Camel ¶
func Cors ¶
func Cors() gin.HandlerFunc
func CurlDeleteWithParam ¶
func CurlPostWithJson ¶
func CurlPostWithParam ¶
func CurlPutWithParam ¶
func FormatSqlTime ¶
func GetLocalIp ¶
func GetLocalIp() string
func GetLocalMac ¶
func GetLocalMac() string
func GetRandomString ¶
func Int64ToString ¶
func IntToString ¶
func Interface2String ¶
func Interface2String(inter interface{}) string
func PKCS5Padding ¶
func PKCS5UnPadding ¶
func ProcessDeleteCode ¶
func ProcessDeleteCode(c *gin.Context, resp *goz.Response, result interface{}) map[string]interface{}
* 处理API返回值 -- DELETE请求
func ProcessGetCode ¶
* 处理API返回值 -- GET请求
func ProcessPostCode ¶
* 处理API返回值 -- POST请求
func ProcessPutCode ¶
* 处理API返回值 -- PUT请求
func ResultSuccess ¶
func RunFuncName ¶
func RunFuncName() string
func SendByKylin ¶
func SendMail ¶
SendMail connects to the server at addr, switches to TLS if possible, authenticates with the optional mechanism a if possible, and then sends an email from address from, to addresses to, with message msg. The addr must include a port, as in "mail.example.com:smtp".
The addresses in the to parameter are the SMTP RCPT addresses.
The msg parameter should be an RFC 822-style email with headers first, a blank line, and then the message body. The lines of msg should be CRLF terminated. The msg headers should usually include fields such as "From", "To", "Subject", and "Cc". Sending "Bcc" messages is accomplished by including an email address in the to parameter but not including it in the msg headers.
The SendMail function and the net/smtp package are low-level mechanisms and provide no support for DKIM signing, MIME attachments (see the mime/multipart package), or other mail functionality. Higher-level packages exist outside of the standard library.
func SendToMail ¶
func SetRequestId ¶
func SetRequestId() gin.HandlerFunc
func StringToInt ¶
func StringToInt64 ¶
func StringToIntWithError ¶
func TimeToLocal ¶
func TlsHandler ¶
func TlsHandler(host string, port string) gin.HandlerFunc
func TokenEncode ¶
func UTCTransLocal ¶
func UTCTransLocalEight ¶
func UtcToLocal ¶
func UtcToLocal2 ¶
Types ¶
type Auth ¶
type Auth interface { // Start begins an authentication with a server. // It returns the name of the authentication protocol // and optionally data to include in the initial AUTH message // sent to the server. It can return proto == "" to indicate // that the authentication should be skipped. // If it returns a non-nil error, the SMTP client aborts // the authentication attempt and closes the connection. Start(server *ServerInfo) (proto string, toServer []byte, err error) // Next continues the authentication. The server has just sent // the fromServer data. If more is true, the server expects a // response, which Next should return as toServer; otherwise // Next should return toServer == nil. // If Next returns a non-nil error, the SMTP client aborts // the authentication attempt and closes the connection. Next(fromServer []byte, more bool) (toServer []byte, err error) }
Auth is implemented by an SMTP authentication mechanism.
func CRAMMD5Auth ¶
CRAMMD5Auth returns an Auth that implements the CRAM-MD5 authentication mechanism as defined in RFC 2195. The returned Auth uses the given username and secret to authenticate to the server using the challenge-response mechanism.
func PlainAuth ¶
PlainAuth returns an Auth that implements the PLAIN authentication mechanism as defined in RFC 4616. The returned Auth uses the given username and password to authenticate to host and act as identity. Usually identity should be the empty string, to act as username.
PlainAuth will only send the credentials if the connection is using TLS or is connected to localhost. Otherwise authentication will fail with an error, without sending the credentials.
type Client ¶
type Client struct { // Text is the textproto.Conn used by the Client. It is exported to allow for // clients to add extensions. Text *textproto.Conn // contains filtered or unexported fields }
A Client represents a client connection to an SMTP server.
func Dial ¶
Dial returns a new Client connected to an SMTP server at addr. The addr must include a port, as in "mail.example.com:smtp".
func NewClient ¶
NewClient returns a new Client using an existing connection and host as a server name to be used when authenticating.
func (*Client) Auth ¶
Auth authenticates a client using the provided authentication mechanism. A failed authentication closes the connection. Only servers that advertise the AUTH extension support this function.
func (*Client) Data ¶
func (c *Client) Data() (io.WriteCloser, error)
Data issues a DATA command to the server and returns a writer that can be used to write the mail headers and body. The caller should close the writer before calling any more methods on c. A call to Data must be preceded by one or more calls to Rcpt.
func (*Client) Extension ¶
Extension reports whether an extension is support by the server. The extension name is case-insensitive. If the extension is supported, Extension also returns a string that contains any parameters the server specifies for the extension.
func (*Client) Hello ¶
Hello sends a HELO or EHLO to the server as the given host name. Calling this method is only necessary if the client needs control over the host name used. The client will introduce itself as "localhost" automatically otherwise. If Hello is called, it must be called before any of the other methods.
func (*Client) Mail ¶
Mail issues a MAIL command to the server using the provided email address. If the server supports the 8BITMIME extension, Mail adds the BODY=8BITMIME parameter. This initiates a mail transaction and is followed by one or more Rcpt calls.
func (*Client) Noop ¶
Noop sends the NOOP command to the server. It does nothing but check that the connection to the server is okay.
func (*Client) Rcpt ¶
Rcpt issues a RCPT command to the server using the provided email address. A call to Rcpt must be preceded by a call to Mail and may be followed by a Data call or another Rcpt call.
func (*Client) Reset ¶
Reset sends the RSET command to the server, aborting the current mail transaction.
func (*Client) StartTLS ¶
StartTLS sends the STARTTLS command and encrypts all further communication. Only servers that advertise the STARTTLS extension support this function.
func (*Client) TLSConnectionState ¶
func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool)
TLSConnectionState returns the client's TLS connection state. The return values are their zero values if StartTLS did not succeed.
type JsonCamelCase ¶
type JsonCamelCase struct {
Value interface{}
}
func (JsonCamelCase) MarshalJSON ¶
func (c JsonCamelCase) MarshalJSON() ([]byte, error)
type ServerInfo ¶
type ServerInfo struct { Name string // SMTP server name TLS bool // using TLS, with valid certificate for Name Auth []string // advertised authentication mechanisms }
ServerInfo records information about an SMTP server.
type UserToken ¶
func TokenDecode ¶
type WSConnection ¶
type WSConnection struct { AllowSend bool ClientId int ClientIp string Conn *websocket.Conn InCh chan []byte OutCh chan []byte ExitCh chan bool // contains filtered or unexported fields }
func NewWSConnection ¶
func NewWSConnection(conn *websocket.Conn) (*WSConnection, error)
* 创建WebSocket连接
func (*WSConnection) ReadMessage ¶
func (conn *WSConnection) ReadMessage() ([]byte, error)
func (*WSConnection) WriteMessage ¶
func (conn *WSConnection) WriteMessage(data []byte) error
Source Files
¶
- AuthChecker.go
- Caml.go
- Cors.go
- CurlRequest.go
- Encrypt.go
- ErrorMsg.go
- GetConfig.go
- GetLocalIp.go
- Helper.go
- Mail.go
- MySQLConnector.go
- ProcessError.go
- RandomString.go
- RedisCache.go
- Request.go
- Result.go
- ScriptExec.go
- SecCheck.go
- ServerTlsHandler.go
- StorageLog.go
- TimeTranfer.go
- Tranform.go
- WebSocket.go
- auth.go
- smtp.go