github.com/astaxie/beego@v1.12.3/utils/mail_test.go (about)

     1  // Copyright 2014 beego Author. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package utils
    16  
    17  import "testing"
    18  
    19  func TestMail(t *testing.T) {
    20  	config := `{"username":"astaxie@gmail.com","password":"astaxie","host":"smtp.gmail.com","port":587}`
    21  	mail := NewEMail(config)
    22  	if mail.Username != "astaxie@gmail.com" {
    23  		t.Fatal("email parse get username error")
    24  	}
    25  	if mail.Password != "astaxie" {
    26  		t.Fatal("email parse get password error")
    27  	}
    28  	if mail.Host != "smtp.gmail.com" {
    29  		t.Fatal("email parse get host error")
    30  	}
    31  	if mail.Port != 587 {
    32  		t.Fatal("email parse get port error")
    33  	}
    34  	mail.To = []string{"xiemengjun@gmail.com"}
    35  	mail.From = "astaxie@gmail.com"
    36  	mail.Subject = "hi, just from beego!"
    37  	mail.Text = "Text Body is, of course, supported!"
    38  	mail.HTML = "<h1>Fancy Html is supported, too!</h1>"
    39  	mail.AttachFile("/Users/astaxie/github/beego/beego.go")
    40  	mail.Send()
    41  }