3

Hi i've a problem whit this code:

# up here there's more code

echo "Password changed" $(date) > lez.txt
curl -n --ssl-reqd --mail-from "me@lupetto.sh" --mail-rcpt "my mail" -T lez.txt --url smtps://smtp.gmail.com:465 --user "example@gmail.com:password"

If I run the script I get only a empty mail, but if I do this manually I get my mail. Thanks.

AnFi
  • 10,493
  • 3
  • 23
  • 47
user3077596
  • 55
  • 1
  • 5
  • 2
    Possibly helpful: http://stackoverflow.com/questions/14722556/using-curl-to-send-email – Simon Dec 12 '13 at 16:56

2 Answers2

5

It looks like it's having problems to find the file contents. What about using a here-string to avoid writing a file at all? Change your code to:

curl -n --ssl-reqd --mail-from "me@lupetto.sh" --mail-rcpt "my mail" -T - --url smtps://smtp.gmail.com:465 --user "example@gmail.com:password" <<<"Password changed $(date)"

Notice the echo statement removal, the here-string at the end of the line and the -T - to get the file from stdin.

Dario Seidl
  • 4,140
  • 1
  • 39
  • 55
bardo
  • 363
  • 2
  • 10
0

cURL expects that the file to be sent has a empty line on the 1st row

the script below will do that for you

##!/bin/sh
# USAGE 
#
# sh emailfile.sh examplefile.log


file="$1"
echo "" > temp | cat "$1" >> temp && mv temp "$1"

wait

curl --url "smtps://smtp.mail.yahoo.com:465" \
     --mail-from "youremail@yahoo.com" \
     --mail-rcpt "dest@domain.com" \
     --user "youremail@yahoo.com:EmailAccountPassword" \
     -T - --silent < "$file"

wait
Mike Holt
  • 4,452
  • 1
  • 17
  • 24
joker
  • 1