本文整理汇总了Golang中github.com/mailgun/mailgun-go.NewMailgun函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMailgun函数的具体用法?Golang NewMailgun怎么用?Golang NewMailgun使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMailgun函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGetStoredMessage
func TestGetStoredMessage(t *testing.T) {
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, "")
id, err := findStoredMessageID(mg) // somehow...
if err != nil {
t.Fatal(err)
}
// First, get our stored message.
msg, err := mg.GetStoredMessage(id)
if err != nil {
t.Fatal(err)
}
fields := map[string]string{
" From": msg.From,
" Sender": msg.Sender,
" Subject": msg.Subject,
"Attachments": fmt.Sprintf("%d", len(msg.Attachments)),
" Headers": fmt.Sprintf("%d", len(msg.MessageHeaders)),
}
for k, v := range fields {
fmt.Printf("%13s: %s\n", k, v)
}
// We're done with it; now delete it.
err = mg.DeleteStoredMessage(id)
if err != nil {
t.Fatal(err)
}
}
开发者ID:adrianlop,项目名称:dex,代码行数:31,代码来源:messages_test.go
示例2: RunApplication
func RunApplication() {
config := CreateConfigFromEnv()
PrintConfig(config)
mg := mailgun.NewMailgun(config.Domain, config.ApiKey, "")
StartHttpServer(mg, config)
}
开发者ID:amyboyd,项目名称:go-mailgun-mailing-list-api,代码行数:9,代码来源:main.go
示例3: TestDeleteTag
func TestDeleteTag(t *testing.T) {
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, "")
err := mg.DeleteTag("newsletter")
if err != nil {
t.Fatal(err)
}
}
开发者ID:9uuso,项目名称:mailgun-go,代码行数:9,代码来源:stats_test.go
示例4: TestSendMGMIME
func TestSendMGMIME(t *testing.T) {
toUser := reqEnv(t, "MG_EMAIL_TO")
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, "")
m := mg.NewMIMEMessage(ioutil.NopCloser(strings.NewReader(exampleMime)), toUser)
msg, id, err := mg.Send(m)
if err != nil {
t.Fatal(err)
}
fmt.Println("TestSendMIME:MSG(" + msg + "),ID(" + id + ")")
}
开发者ID:adrianlop,项目名称:dex,代码行数:12,代码来源:messages_test.go
示例5: TestSendLegacyPlain
func TestSendLegacyPlain(t *testing.T) {
toUser := reqEnv(t, "MG_EMAIL_TO")
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
publicApiKey := reqEnv(t, "MG_PUBLIC_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, publicApiKey)
m := mailgun.NewMessage(fromUser, exampleSubject, exampleText, toUser)
msg, id, err := mg.Send(m)
if err != nil {
t.Fatal(err)
}
fmt.Println("TestSendPlain:MSG(" + msg + "),ID(" + id + ")")
}
开发者ID:adrianlop,项目名称:dex,代码行数:13,代码来源:messages_test.go
示例6: TestSendMGPlainAt
func TestSendMGPlainAt(t *testing.T) {
toUser := reqEnv(t, "MG_EMAIL_TO")
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
publicApiKey := reqEnv(t, "MG_PUBLIC_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, publicApiKey)
m := mg.NewMessage(fromUser, exampleSubject, exampleText, toUser)
m.SetDeliveryTime(time.Now().Add(5 * time.Minute))
msg, id, err := mg.Send(m)
if err != nil {
t.Fatal(err)
}
fmt.Println("TestSendPlainAt:MSG(" + msg + "),ID(" + id + ")")
}
开发者ID:adrianlop,项目名称:dex,代码行数:14,代码来源:messages_test.go
示例7: TestGetBounces
func TestGetBounces(t *testing.T) {
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, "")
n, bounces, err := mg.GetBounces(-1, -1)
if err != nil {
t.Fatal(err)
}
if n > 0 {
t.Fatal("Expected no bounces for what should be a clean domain.")
}
if n != len(bounces) {
t.Fatalf("Expected length of bounces %d to equal returned length %d", len(bounces), n)
}
}
开发者ID:9uuso,项目名称:mailgun-go,代码行数:15,代码来源:bounces_test.go
示例8: Emailer
func (cfg MailgunEmailerConfig) Emailer(fromAddr string) (Emailer, error) {
from := cfg.FromAddr
if from == "" {
from = fromAddr
}
if from == "" {
return nil, errors.New(`missing "from" field in email config`)
}
mg := mailgun.NewMailgun(cfg.Domain, cfg.PrivateAPIKey, cfg.PublicAPIKey)
return &mailgunEmailer{
mg: mg,
from: from,
}, nil
}
开发者ID:Tecsisa,项目名称:dex,代码行数:15,代码来源:mailgun.go
示例9: sendWithMailgun
// sendWithMailgun handles the main send and logging logic for any single email deploy
func (c *Client) sendWithMailgun() (string, error) {
var err error
c.Body, err = c.prepareTmpl()
if err != nil {
return "", err
}
gun := mg.NewMailgun(Conf["mailgun"]["domain"], Conf["mailgun"]["secret"], Conf["mailgun"]["public"])
// override the http client
client := urlfetch.Client(c.context)
gun.SetClient(client)
// generate mailgun message
message := mg.NewMessage(fmt.Sprintf("%s <%s>", Conf["default"]["fromname"], Conf["default"]["fromemail"]), c.Subject, c.Body, c.Recipient[0].Render)
message.SetHtml(strings.Replace(c.Body, "\\", "", -1))
// add additional recipients
for k, v := range c.Recipient {
if k > 0 {
err := message.AddRecipient(v.Render)
if err != nil {
c.context.Errorf("Could not append [%s] as Mailgun recipient: %v", v.Render, err)
return "", err
}
}
}
// send the email
_, id, err := gun.Send(message)
if err != nil {
c.context.Errorf("Error: %v", err)
return "", err
}
if Conf["default"]["logmessages"] == "true" {
// if the id is not empty then add to the message log
if id != "" {
_, logErr := c.addMessageLog()
if logErr != nil {
c.context.Errorf("Failed to add message to log: %v", logErr)
}
}
}
return id, err
}
开发者ID:markhayden,项目名称:go-go-mailman,代码行数:49,代码来源:mailgun.go
示例10: NotifyUser
func NotifyUser(name, email, subject, message string) {
fmt.Printf("Notifying %s with subject:\n", email)
fmt.Printf("%s\n", subject)
mailto := fmt.Sprintf("%s <%s>", name, email)
gun := mailgun.NewMailgun("mail.ckpt.no", os.Getenv("CKPT_MAILGUN_KEY"), "pubkey-b3e133632123a0da24d1e2c5842039b6")
m := mailgun.NewMessage("CKPT <[email protected]>", subject, message, mailto)
m.AddHeader("Content-Type", "text/plain; charset=\"utf-8\"")
response, id, err := gun.Send(m)
if err != nil {
fmt.Printf("Error:\n%+v\n", err.Error())
}
fmt.Printf("Response ID: %s\n", id)
fmt.Printf("Message from server: %s\n", response)
}
开发者ID:ckpt,项目名称:backend-services,代码行数:16,代码来源:notify.go
示例11: TestSendMGBatchFailRecipients
func TestSendMGBatchFailRecipients(t *testing.T) {
toUser := reqEnv(t, "MG_EMAIL_TO")
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, "")
m := mg.NewMessage(fromUser, exampleSubject, exampleText+"Batch\n")
for i := 0; i < mailgun.MaxNumberOfRecipients; i++ {
m.AddRecipient("") // We expect this to indicate a failure at the API
}
err := m.AddRecipientAndVariables(toUser, nil)
if err == nil {
// If we're here, either the SDK didn't send the message,
// OR the API didn't check for empty To: headers.
t.Fatal("Expected to fail!!")
}
}
开发者ID:adrianlop,项目名称:dex,代码行数:16,代码来源:messages_test.go
示例12: TestSendMGTag
func TestSendMGTag(t *testing.T) {
toUser := reqEnv(t, "MG_EMAIL_TO")
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
publicApiKey := reqEnv(t, "MG_PUBLIC_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, publicApiKey)
m := mg.NewMessage(fromUser, exampleSubject, exampleText+"Tags Galore!\n", toUser)
m.AddTag("FooTag")
m.AddTag("BarTag")
m.AddTag("BlortTag")
msg, id, err := mg.Send(m)
if err != nil {
t.Fatal(err)
}
fmt.Println("TestSendTag:MSG(" + msg + "),ID(" + id + ")")
}
开发者ID:adrianlop,项目名称:dex,代码行数:16,代码来源:messages_test.go
示例13: TestGetCredentials
func TestGetCredentials(t *testing.T) {
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, "")
n, cs, err := mg.GetCredentials(mailgun.DefaultLimit, mailgun.DefaultSkip)
if err != nil {
t.Fatal(err)
}
tw := &tabwriter.Writer{}
tw.Init(os.Stdout, 2, 8, 2, ' ', 0)
fmt.Fprintf(tw, "Login\tCreated At\t\n")
for _, c := range cs {
fmt.Fprintf(tw, "%s\t%s\t\n", c.Login, c.CreatedAt)
}
tw.Flush()
fmt.Printf("%d credentials listed out of %d\n", len(cs), n)
}
开发者ID:9uuso,项目名称:mailgun-go,代码行数:17,代码来源:credentials_test.go
示例14: setup
func setup(t *testing.T) (mailgun.Mailgun, string) {
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, "")
address := fmt.Sprintf("[email protected]%s", domain)
_, err := mg.CreateList(mailgun.List{
Address: address,
Name: address,
Description: "TestMailingListMembers-related mailing list",
AccessLevel: mailgun.Members,
})
if err != nil {
t.Fatal(err)
}
return mg, address
}
开发者ID:9uuso,项目名称:mailgun-go,代码行数:17,代码来源:mailing_lists_test.go
示例15: TestGetSingleBounce
func TestGetSingleBounce(t *testing.T) {
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, "")
exampleEmail := fmt.Sprintf("[email protected]%s", domain)
_, err := mg.GetSingleBounce(exampleEmail)
if err == nil {
t.Fatal("Did not expect a bounce to exist")
}
ure, ok := err.(*mailgun.UnexpectedResponseError)
if !ok {
t.Fatal("Expected UnexpectedResponseError")
}
if ure.Actual != 404 {
t.Fatalf("Expected 404 response code; got %d", ure.Actual)
}
}
开发者ID:9uuso,项目名称:mailgun-go,代码行数:17,代码来源:bounces_test.go
示例16: TestSendMGBatchRecipientVariables
func TestSendMGBatchRecipientVariables(t *testing.T) {
toUser := reqEnv(t, "MG_EMAIL_TO")
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, "")
m := mg.NewMessage(fromUser, exampleSubject, templateText)
err := m.AddRecipientAndVariables(toUser, map[string]interface{}{
"name": "Joe Cool Example",
"table": 42,
})
if err != nil {
t.Fatal(err)
}
_, _, err = mg.Send(m)
if err != nil {
t.Fatal(err)
}
}
开发者ID:adrianlop,项目名称:dex,代码行数:18,代码来源:messages_test.go
示例17: TestGetStats
func TestGetStats(t *testing.T) {
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, "")
totalCount, stats, err := mg.GetStats(-1, -1, nil, "sent", "opened")
if err != nil {
t.Fatal(err)
}
fmt.Printf("Total Count: %d\n", totalCount)
tw := tabwriter.NewWriter(os.Stdout, 2, 8, 2, ' ', tabwriter.AlignRight)
fmt.Fprintf(tw, "Id\tEvent\tCreatedAt\tTotalCount\t\n")
for _, stat := range stats {
fmt.Fprintf(tw, "%s\t%s\t%s\t%d\t\n", stat.Id, stat.Event, stat.CreatedAt, stat.TotalCount)
}
tw.Flush()
}
开发者ID:9uuso,项目名称:mailgun-go,代码行数:18,代码来源:stats_test.go
示例18: TestCreateDestroyUnsubscription
func TestCreateDestroyUnsubscription(t *testing.T) {
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
email := reqEnv(t, "MG_EMAIL_ADDR")
mg := mailgun.NewMailgun(domain, apiKey, "")
// Create unsubscription record
err := mg.Unsubscribe(email, "*")
if err != nil {
t.Fatal(err)
}
// Destroy the unsubscription record
err = mg.RemoveUnsubscribe(email)
if err != nil {
t.Fatal(err)
}
}
开发者ID:9uuso,项目名称:mailgun-go,代码行数:18,代码来源:unsubscribes_test.go
示例19: TestGetUnsubscribes
func TestGetUnsubscribes(t *testing.T) {
domain := reqEnv(t, "MG_DOMAIN")
apiKey := reqEnv(t, "MG_API_KEY")
mg := mailgun.NewMailgun(domain, apiKey, "")
n, us, err := mg.GetUnsubscribes(mailgun.DefaultLimit, mailgun.DefaultSkip)
if err != nil {
t.Fatal(err)
}
fmt.Printf("Received %d out of %d unsubscribe records.\n", len(us), n)
if len(us) > 0 {
tw := &tabwriter.Writer{}
tw.Init(os.Stdout, 2, 8, 2, ' ', 0)
fmt.Fprintln(tw, "ID\tAddress\tCreated At\tTag\t")
for _, u := range us {
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t\n", u.ID, u.Address, u.CreatedAt, u.Tag)
}
tw.Flush()
}
}
开发者ID:9uuso,项目名称:mailgun-go,代码行数:19,代码来源:unsubscribes_test.go
示例20: Send
func (m *mailgunner) Send(msg string, sender string, subject string, to string) error {
if len(strings.TrimSpace(sender)) <= 0 {
sender = "Kishore CEO <[email protected]>"
}
mg := mailgun.NewMailgun(m.domain, m.api_key, "")
g := mailgun.NewMessage(
sender,
subject,
"You are in !",
to,
)
g.SetHtml(msg)
g.SetTracking(true)
_, id, err := mg.Send(g)
if err != nil {
return err
}
log.Infof("Mailgun sent %s", id)
return nil
}
开发者ID:vijaykanthm28,项目名称:vertice,代码行数:20,代码来源:mailgun.go
注:本文中的github.com/mailgun/mailgun-go.NewMailgun函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论