-
-
Save ctigeek/d79484ccbaec7e71a837 to your computer and use it in GitHub Desktop.
function Send-MailgunEmail($from, $to, $subject, $body, $emaildomain, $apikey) { | |
$idpass = "api:$($apikey)" | |
$basicauth = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($idpass)) | |
$headers = @{ | |
Authorization = "Basic $basicauth" | |
} | |
$url = "https://api.mailgun.net/v2/$($emaildomain)/messages" | |
$body = @{ | |
from = $from; | |
to = $to; | |
subject = $subject; | |
text = $body | |
} | |
Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $body | |
} |
Is it possible to pass multiple tags (o:tag) using this method?
@jwalker55
In order to add multiple tags, you will need to build your own body string since the powershell hash created can't have multiple entries with the same name.
Any way you can point me in the right direction to start building a body string? Not sure where to start
@jwalker55
So it would be something like:
$body = "from=" + [uri]::EscapeDataString($from) + "&to="+[uri]::EscapeDataString($to) + "&subject=" + [uri]::EscapeDataString($subject) + "&text=" + [uri]::EscapeDataString($body)
Just follow the same pattern to add as many o:tag
entries as you like.
When manually creating the body, you probably also need to add the content-type to $headers
:
"Content-Type"="application/x-www-form-urlencoded"
.
Ahhh ok. Tremendous help. Thank you!
anyways to add attachment to email using mailgun ?
Is there a way to add attachments?
I've tried adding the header
"Content-type" = "multipart/form-data";
and aattachment
field to the $body, but Mailgun returns 400 bad request.