Send Email¶
Examples¶
Go¶
The syntax to send email in a Golang node is :
u.SendMail(bodyHtml, substitutions, subject, recipients)
Below is an example of using the syntax and a description of its function arguments:
mp := make(map[string]string)
mp["first"] = "Hello"
mp["last"] = "There"
u.SendMail("Body.html", mp, "hello there", []string{"[email protected]", "market"})
bodyHtml
- The body of the email can be passed from a HTML file in the playpen/input
directory or by directly passing the template string to the function:
{% raw %}
body := `{{$.first}}
{{$.last}}`
{% endraw %}
u.SendMail(body, mp, "hello there", []string{"[email protected]"})
substitutions
- Substitutions are performed on the matching keys in the HTML content.
The example HTML file would be:
{% raw %}
{{$.first}}
{{$.last}}
{% endraw %}
When the mail is sent these become Hello, and There respectively. The mail is sent from the configured email account.
subject
- The email subject
recipients
- recipients takes in a string array of recipients.
This can be a combination of email addresses or the name of the group that the
email addresses are subscribed to.
The default email configuration is used to send the mail notifications. You can also pass your own custom configuration (e.g. for testing purposes) using the following syntax:
u.SendMailWithConfig(bodyHtml, substitutions, subject, recipients, &mailConfiguration{
Username: "user",
Password: "SecR3t",
Port: 123,
Host: "smtp.gmail.com" ,
Sender: "[email protected]",
})
Mail Configuration | Description |
---|---|
Username | username to authenticate to the SMTP server. Must use with Password |
Password | password to authenticate to the SMTP server. Must use with Username |
Port | SMTP port |
Host | SMTP endpoint |
Sender | the "FROM" address |
You can specify only the configurations that you wish to change and leave out the rest.
Python¶
The syntax to send mail in a Python node is :
from sdk import mail
mail.SendMail(bodyHtml, substitutions, subject, recipients)
Below is an example of using the syntax and a description of its function arguments:
from sdk import mail
mp = dict()
mp["first"] = "Hello"
mp["last"] = "There"
mail.SendMail("Body.html", mp, "hello there", ("[email protected]"))
bodyHtml
- The body of the email can be passed from a HTML file in the playpen/input
directory or by directly passing the template string to the function:
{% raw %}
body = """{{$.first}}
{{$.last}}"""
{% endraw %}
mail.SendMail(body, mp, "hello there", ["[email protected]"])
substitutions
- Substitutions are performed on the matching keys in the HTML content.
The example HTML file would be:
{% raw %}
{{$.first}}
{{$.last}}
{% endraw %}
When the mail is sent these become Hello, and There respectively. The mail is sent from the configured email account.
subject
- The email subject
recipients
- recipients takes in a string array of recipients.
This can be a combination of email addresses or the name of the group that the
email addresses are subscribed to.
The default email configuration is used to send the mail notifications. You can also pass your own custom configuration (e.g. for testing purposes) using the following syntax:
mail.SendMail(bodyHtml, substitutions, subject, recipients, mail.MailConfiguration(
"user","SecR3t",123,"smtp.gmail.com","[email protected]"))
Mail Configuration | Description |
---|---|
Username | username to authenticate to the SMTP server. Must use with Password. |
Password | password to authenticate to the SMTP server. Must use with Username. |
Port | SMTP port |
Host | SMTP endpoint |
Sender | the "FROM" address |
You can specify only the configurations that you wish to change and leave out the rest.