Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows curl Batch file

I want to make a mailgun curl call using windows batch file. Since windows shell doesn't support multiple lines, how can I execute the below curl function in windows batch file?

curl -s --user 'api:key-xxxxxxxxxx' \
    https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages \
    -F from='user <[email protected]>' \
    -F to='user <[email protected]>' \
    -F subject='Hello' \
    -F text='body!' \
    -F [email protected] \

Update

When I tried to execute the command after removing the multiple lines it returned this error:

    curl -s --user 'api:key-xxxxxxxxxx' https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages -F from='user  -F to='user  -F subject='Hello' -F text='body!' -F [email protected] 0<[email protected] 1>'
The system cannot find the file specified.

PS: The attachment file is in the same directory

Thanks!

like image 317
Ganesh Rathinavel Avatar asked Feb 07 '23 17:02

Ganesh Rathinavel


1 Answers

simply on one line and put the <> redirection char between " or escape it with ^:

curl -s --user 'api:key-xxxxxxxxxx' https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages -F from="user <[email protected]>" -F to="user <[email protected]>" -F subject='Hello' -F text='body!' -F [email protected]

You can also create variable for each element :

set "$ApiKey=api:key-xxxxxxxxxx"
set "$Url=https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages"
set "[email protected]"
....

and then 

curl -s --user '%$ApiKey%' %$Url% -F from="user <%$From%>" -F to= ....
like image 125
SachaDee Avatar answered Feb 11 '23 23:02

SachaDee