खोज…


वाक्य - विन्यास

  • func PlainAuth (पहचान, उपयोगकर्ता नाम, पासवर्ड, होस्ट स्ट्रिंग) प्रामाणिक
  • func SendMail (Addr string, एक Auth, स्ट्रिंग से, [] string, msg [] byte) त्रुटि के लिए

Smtp.SendMail के साथ ईमेल भेजना ()

ईमेल भेजना गो में बहुत सरल है। यह RFC 822 को समझने में मदद करता है, जो उस शैली को निर्दिष्ट करता है जिसमें एक ईमेल की आवश्यकता होती है, नीचे दिया गया कोड RFC 822 अनुरूप ईमेल भेजता है।

package main

import (
    "fmt"
    "net/smtp"
)

func main() {
    // user we are authorizing as
    from := "[email protected]"

    // use we are sending email to
    to := "[email protected]"

    // server we are authorized to send email through
    host := "mail.example.com"

    // Create the authentication for the SendMail()
    // using PlainText, but other authentication methods are encouraged
    auth := smtp.PlainAuth("", from, "password", host)

    // NOTE: Using the backtick here ` works like a heredoc, which is why all the 
    // rest of the lines are forced to the beginning of the line, otherwise the 
    // formatting is wrong for the RFC 822 style
    message := `To: "Some User" <[email protected]>
From: "Other User" <[email protected]>
Subject: Testing Email From Go!!

This is the message we are sending. That's it!
`

    if err := smtp.SendMail(host+":25", auth, from, []string{to}, []byte(message)); err != nil {
        fmt.Println("Error SendMail: ", err)
        os.Exit(1)
    }
    fmt.Println("Email Sent!")
}

उपर्युक्त जैसा संदेश भेजेगा:

To: "Other User" <[email protected]>
From: "Some User" <[email protected]>
Subject: Testing Email From Go!!

This is the message we are sending. That's it!
.


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow