I tried to send this by email. I tried a lot of ways and always I obteined the same thing: an error.
http://goto-21.net/campaign/htmlversion?mkt_hm=0&AdministratorID=47507&CampaignID=58&StatisticID=62&MemberID=733807&s=994508d6292a660150ccc60c3f0310d4&isDemo=0
I tried with this:
curl -s --user 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0' \
Xhttps://api.mailgun.net/v2/samples.mailgun.org/messages \
-F from='Excited User ' \
-F to='foo#example.com' \
-F cc='bar#example.com' \
-F bcc='baz#example.com' \
-F subject='Hello' \
-F text='Testing some Mailgun awesomness!' \
-F html=' CODE HERE ' \
And this:
curl -s --user 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0' \
Xhttps://api.mailgun.net/v2/samples.mailgun.org/messages \
-F from='Excited User ' \
-F to='foo#example.com' \
-F cc='bar#example.com' \
-F bcc='baz#example.com' \
-F subject='Hello' \
-F text='Testing some Mailgun awesomness!' \
--form-string html=' CODE HERE ' \
But it doesnt work...Always ''syntax error''
Anyone can help me?
Thank you!
Use the following cURL command to send HTML emails using the command line.
Replace the uppercase parameter with your own and you're ready to send!
curl -s --user 'api:YOUR-API-KEY' https://api.mailgun.net/v2/YOURDOMAIN/messages -F from='YOU#YOURPROVIDER.COM' -F to=RECEIVER#PROVIDER.com -F subject='Hello World with HTML' -F html='<html><head><title>Hello</title></head><body>Hello <strong>World</strong></body></html>' -F text='Hello world'
What this does is send an email from an address attached to your domain to a receiver sending html and plain text version as a fall back!
Happy mailgunning
Best,
the origin request is looks like:
curl -s --user 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0' \
https://api.mailgun.net/v3/samples.mailgun.org/messages \
-F from='Excited User <excited#samples.mailgun.org>' \
-F to='devs#mailgun.net' \
-F subject='Hello' \
-F text='Testing some Mailgun awesomeness!'
but you have a big X before https.
curl -s --user 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0' \
-------> X <----- https://api.mailgun.net/v2/samples.mailgun.org/messages \ -F from='Excited User ' \ -F to='foo#example.com' \ -F cc='bar#example.com' \ -F bcc='baz#example.com' \ -F subject='Hello' \ -F text='Testing some Mailgun awesomness!' \ --form-string html=' CODE HERE ' \
maybe this cause an error
Related
I'm doing a bash script, when working out such an error ... I can't figure out what the problem is. I'm not good at scripting yet.
#!/bin/bash
data=LOGIN
password=123PASSWD
note_link=$(curl -s 'https://cryptgeon.nicco.io' \
-H 'X-Requested-With: XMLHttpRequest' \
--data-urlencode "data=$data" \
--data "has_manual_pass=false&duration_hours=0&dont_ask=false&data_type=T¬ify_email=¬ify_ref=" \
| jq -r --arg arg $password '.note_link + "#" + $arg')
echo "note URL is $note_link"
curl's -s option is silencing the errors as well, but you want to see the errors in this case to be able to understand what is going wrong, so use -sS instead.
Also, jq can only parse json. If the input is not json, it will fail with the error you get. You should first try to parse the output with jq, and if it fails, display it.
#!/bin/bash
data=LOGIN
password=123PASSWD
curl_output=$(curl -sS 'https://cryptgeon.nicco.io' \
-H 'X-Requested-With: XMLHttpRequest' \
--data-urlencode "data=$data" \
--data "has_manual_pass=false&duration_hours=0&dont_ask=false&data_type=T¬ify_email=¬ify_ref=")
if note_link=$(jq -r --arg pass "$password" '.note_link + "#" + $pass' <<<"$curl_output" 2>/dev/null); then
echo "note URL is $note_link"
else
printf >&2 %s\\n "Could not parse the curl output:" "$curl_output"
fi
I am trying to upload a file to Github using its API.
Following code works, but only with smaller size content which is approx less than 1MB.
tar -czvf logs.tar.gz a.log b.log
base64_logs=$(base64 logs.tar.gz | tr -d \\n)
content_response=$(curl \
-X PUT \
-u :"$GIT_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"$content_url" \
-d '{"message": "Log files", "content": "'"$base64_logs"'"}')
For content that is a bit large, I get the following error:
/usr/bin/curl: Argument list too long
Now, there is already a question on SO about this error message, and it says that to upload a file directly. See here: curl: argument list too long
When I try this, I get a problem parsing JSON error message.
tar -czvf logs.tar.gz a.log b.log
base64_logs=$( base64 logs.tar.gz | tr -d \\ ) > base64_logs.txt
content_response=$(curl \
-X PUT \
-u :"$GIT_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"$content_url" \
-d '{"message": "Log files", "content": #base64_logs.txt}')
Can anyone point me out where I am making mistake here? Thanks!
Use the base64 command rather than the #base64 filter from jq, because the later can only encode textual data and not binary data as from a .gz archive.
Pipe the base64 stream to jq to format it into a JSON data stream.
Curl will read the JSON data stream and send it.
# use base64 to encode binary data and -w0 all in one-line stream
base64 --wrap=0 logs.tar.gz |
# JSON format from raw input
jq \
--raw-input \
--compact-output \
'{"message": "Log files", "content": . }' |
# Pipe JSON to curl
curl \
--request PUT \
--user ":$GIT_TOKEN" \
--header "Accept: application/vnd.github.v3+json" \
--header 'Content-Type: application/json' \
--data-binary #- \
--url "$content_url"
I tried the following command to capture the output of a command (grep as an example) with color. But the result is shown as ^[[01;31m^[[Ka^[[m^[[K.
grep --color=always a <<< a |
a2ps -=book -B -q --medium=A4dj --borders=no -o out1.ps &&
gs \
-sDEVICE=png16m \
-dNOPAUSE -dBATCH -dSAFER \
-dTextAlphaBits=4 -q \
-r300x300 \
-sOutputFile=out2.png out1.ps
Is there a way to capture the color in the image? Thanks.
Trying to send a weekly overview of the backup size from a bash script which does a curl to send a message.
echo $(curl -s \
-X POST \
--user "aasdfasdfbc:4adgadfgsdfg" \
https://api.mailjet.com/v3/send \
-H "Content-Type: application/json" \
-d '{
"FromEmail":"noreply#bashdrsh.li",
"FromName":"Backup Notification",
"Recipients": [
{
"Email":"back.upper#bashdrsh.li"
}
],
"Subject":"['"$host"'] Backup overview",
"Text-part":"Backup on '"$host"' weekly overview\n\n '"$(find /tmp/backup/2017-07-12/ -maxdepth 1 -type f -exec ls -hls {} \; | awk '{ printf "%-40s %30s\n", $10, $6 }')"'\n"
}')
But the find command always returns with this response
find: paths must precede expression: globals-only.7z
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec|time] [path...] [expression]
{
"FromEmail":"noreply#bashdrsh.li",
"FromName":"Backup Notification",
"Recipients": [
{
"Email":"back.upper#bashdrsh.li"
}
],
"Subject":"[MYLOCAL] Backup overview",
"Text-part":"Backup on MYLOCAL weekly overview\n\n \n"
}
Running the find command on command line it returns everything as expected
# find /tmp/backup/2017-07-12/ -name '*.7z' -exec ls -hls {} \; | awk '{ printf "%-40s %30s\n", $10, $6 }'
/tmp/backup/2017-07-12/globals-only.7z 7.3K
/tmp/backup/2017-07-12/auth.7z 759
How can I include a nice formatted table into the message?
You're not using the same find expression in curl invocation and later on command line. Also, no need for ls & awk.
Try replacing your complete command substitution with:
find /tmp/backup/2017-07-12/ -name '*.7z' -printf "%-40P %30s\n"
For readability, you can store that into a variable, and use like:
output=$(find /tmp/backup/2017-07-12/ -name '*.7z' -printf "%-40P %30s\n")
echo $(curl -s \
-X POST \
--user "aasdfasdfbc:4adgadfgsdfg" \
https://api.mailjet.com/v3/send \
-H "Content-Type: application/json" \
-d '{
"FromEmail":"noreply#bashdrsh.li",
"FromName":"Backup Notification",
"Recipients": [
{
"Email":"back.upper#bashdrsh.li"
}
],
"Subject":"['"$host"'] Backup overview",
"Text-part":"Backup on '"$host"' weekly overview\n\n '"$output"'\n"
}')
Let's take the following example:
curl -i -X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "Player.Open", "params":{"item":false}}' \
http://example.com/jsonrpc
Now I want to have the boolean value of "item" be set in a shell script variable such as:
PRIVATE=false
read -p "Is this a private? (y/[n]) " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
PRIVATE=true
fi
And I want to pass in the value of PRIVATE to item. I have tried every which way but no luck. Can anyone shed some light?
You can do it this way:
curl -i -X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "Player.Open", "params":{"item":'"$PRIVATE"'}}' \
http://example.com/jsonrpc
Instead of your existing -d ... line above, you could try the following:
-d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.Open\", \"params\":{\"item\":$PRIVATE}}" \
That is: when using double quote speechmarks ("), bash substitutes values for variables referenced $LIKE_THIS (not the case for single quotes you were using). The downside is that you then need to escape any double-quotes in the string itself (using the backslash, as above).
This abomination works too.
$ npm run script -- madrid
# script
json='{"city":"'"$1"'"}'
curl -X POST -d $json http://localhost:5678/api/v1/weather