Hi, I want to format the msg.body property for an email.
I have two variable (lat & lon) for storing the location data. then I am formatting a link to match the google-maps links. This way the receiver should be able to open te link in google maps.
my msg.body looks like this:
msg.body = "Google Maps" + lat + "," + lon;
I am sending through a powershell script, because I want to change the user/password in the dashboard. I am using the below code to run the script.
The body of the email should be the link, but i get:
so somehow the "/" is converted to /. What am I doing wrong?
$EmailTo = "{{toemail}}"
$EmailFrom = "{{fromemail}}"
$Subject = "{{subject}}"
$Body = "{{body}}"
$SMTPServer = "{{smtpserver}}"
$SMTPPort = "{{smtmpport}}"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, $SMTPPort)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("{{loginuser}}", "{{loginpass}}");
$SMTPClient.Send($SMTPMessage)
I simplified the email like this:
[
{
"id": "84540a1d29575b19",
"type": "template",
"z": "3d58124abc08a456",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "$EmailTo = \"{{toemail}}\"\n$EmailFrom = \"{{fromemail}}\"\n$Subject = \"{{subject}}\" \n$Body = \"{{body}}\" \n$SMTPServer = \"{{smtpserver}}\" \n$SMTPPort = \"{{smtmpport}}\"\n$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)\n$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, $SMTPPort) \n$SMTPClient.EnableSsl = $true \n$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(\"{{loginuser}}\", \"{{loginpass}}\"); \n$SMTPClient.Send($SMTPMessage)",
"output": "str",
"x": 940,
"y": 1320,
"wires": [
[
"21f793304c283f0a",
"a8527b09e15f4de1"
]
]
},
{
"id": "21f793304c283f0a",
"type": "powershell",
"z": "3d58124abc08a456",
"name": "",
"x": 1190,
"y": 1260,
"wires": [
[],
[]
]
},
{
"id": "a8527b09e15f4de1",
"type": "debug",
"z": "3d58124abc08a456",
"name": "simple mail output",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1190,
"y": 1320,
"wires": []
},
{
"id": "e62801d6acc7e33f",
"type": "function",
"z": "3d58124abc08a456",
"name": "Format email",
"func": "\nvar lat = \"LAT\";\nvar lon = \"LON\"\n\n\nmsg.body = \"https://maps.google.com/?q=\" + lat + \",\" + lon;\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 730,
"y": 1320,
"wires": [
[
"84540a1d29575b19",
"6d5711d16d95e02b"
]
]
},
{
"id": "6d5711d16d95e02b",
"type": "debug",
"z": "3d58124abc08a456",
"name": "check flow variables",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1200,
"y": 1220,
"wires": []
},
{
"id": "71744ca1a1c4e1e0",
"type": "inject",
"z": "3d58124abc08a456",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 530,
"y": 1320,
"wires": [
[
"e62801d6acc7e33f"
]
]
}
]
Her you can find some more details about the flow I am using:
https://flows.nodered.org/flow/6eef931189ce2697f7747dc976774367