I want to actually call the following in Ruby
echo "<html><body><b>BOLD</b></body></html>" | mutt -e "set content_type=text/html" -s "HTML content" -- anushka.misra2#gmail.com
I was successfully able to do it in Ruby with system() method:
system 'echo "<html><body><b>BOLD</b></body></html>" | mutt -e "set content_type=text/html" -s "HTML content" -- anushka.misra2#gmail.com'
Now, I want email to be a variable:
email = anushka.misra2#gmail.com
system 'echo "<html><body><b>BOLD</b></body></html>" | mutt -e "set content_type=text/html" -s "HTML content" -- $email'
But this fails as it doesn't evaluate email variable. How do I fix it?
system %Q{echo "<html><body><b>BOLD</b></body></html>" | mutt -e "set content_type=text/html" -s "HTML content" -- #{email}}
#{foo} is the Ruby way to add a value into a string. #{foo} is only evaluated in strings with " (not '). Where %Q{} does the same, but you do not have to escape " inside the string.
Related
I have a text that I wanted to simplify, by removing the unicode characters. It works fine when I run in bash, but I get a strange error when I run it in AppleScript.
set mytext to "SomeApp™ on the App Store"
log (do shell script "echo '" & mytext & "' | /usr/bin/iconv -c -s -f utf-8 -t ascii")
The reply is:
tell current application
do shell script "echo 'SomeApp™ on the App Store' | /usr/bin/iconv -c -s -f utf-8 -t ascii"
--> error "SomeApp on the AppStore" number 1
Result:
error "SomeApp on the AppStore" number 1
It appears that, while the -c -s options prevent iconv from printing errors due to untranslatable characters, it'll still exit with an error status (specifically, a status of 1); AppleScript is detecting this and reporting it (that's the "number 1" part of its message). Here's an example of the same effect in the shell:
$ echo "SomeApp™ on the App Store" | /usr/bin/iconv -c -s -f utf-8 -t ascii || echo "There was an error, status = $?"
SomeApp on the App Store
There was an error, status = 1
You can suppress this by adding || true to the shell command, which will make the overall command succeed even if iconv "fails". Unfortunately, it'll also prevent AppleScript from detecting other -- real -- errors; I don't know a way to fix this.
I'd also recommend using quoted form of rather than manually adding quotes around the string (which will fail completely if the string contains ASCII apostrophes). Something like this:
set mytext to "SomeApp™ on the App Store"
log (do shell script "echo " & (quoted form of mytext) & " | /usr/bin/iconv -c -s -f utf-8 -t ascii || true")
I am trying to sending mail with attachment using shell script, but I am not getting mail.
Shell Script
#!/bin/bash
$ echo "Mail Sent" | mail -s "a subject" -a "Report_by_Customer_20190614_131246.xls" test#gmail.com
Use mutt. Add list of files that you want to attach
echo "body" | mutt -s "subject" -a attachment0 attachment1 [...] -- test#gmail.com
Also here you can find another options
I'm trying to send an email in this way:
path_to_file="/home/username/tmp/filename.html"
subject="My Subject"
to.each do |address|
cmd = "`echo \"#{body}\" | mutt -s \"#{subject}\" #{address} -a #{path_to_file}`"
system(cmd)
end
end
This is running on a unix machine, the file has an html extenxion and contains html code.
I receive the file correctly, with the same filename and extension, the problem is that is completely empty, this is strange because when i run the same command (mutt) from the terminal, applying the same path to file:
echo "body here" | mutt -s "some subject" mamail#mail.com -a ${path_to_file}
Then it works just fine.
Any idea?
I have a requirement where I need to send two files A and B . The file A's content should be displayed as in-line or body of the mail and file B as an attachment.
Is multiple attachment using mutt is possible?
The command
echo "Hello everyone " | mutt -s 'My mail ' abc#gmail.com -a myFile.txt
is writing Hello everyone as body of the mail and myFile.txt as an attachment(inline).
Both of my files A and B are dynamically generated, so I cannot have an echo statement.
It's actually very simple:
mutt -s 'My mail ' abc#gmail.com -a report1.txt < report2.txt
If you had two scripts to create the reports, you could use pipes (i.e. no files would be created on disk):
script2 | mutt -s 'My mail ' abc#gmail.com -a <(script1)
cat A | mutt -s 'My mail' abc#gmail.com -a B
If the shell script prints file A's content to standard output, like this:
script >A
then you can use tee to print both to the file A and into the pipe to mutt:
script | tee A | mutt -s 'My mail' abc#gmail.com -a B
I am trying to run a long bash script overnight to get some data. I wanted to include a script that would automatically e-mail me the files after the scripts are completed. Is there a way to do this using mutt? I want something like below:
sh atoms.sh
sh angles.sh
mutt -a atoms.dat angles.dat -- [e-mail adress]
Any takers?
EDITS: If there's any other way to achieve this -- "sending multiple attachment to an e-mail address after scripting is finished" -- I'd be very appreciated.
sh atoms.sh
sh angles.sh
mutt -s "data set from atoms.sh" [email address] < ./atom.dat
mutt -s "data set from angles.sh" [email address] < ./angles.dat
will disable the terminal interaction and send e-mails after the jobs are finished
-a file [...]
Attach a file to your message using MIME. To attach multiple files, separating
filenames and recipient addresses with "--" is mandatory, e.g. mutt -a img.jpg
*.png -- addr1 addr2.
$ $( sh atoms.sh; sh angles.sh ) && mutt -s "man mutt" \
-a grab.sh raptor.mpd.ogg.m3u scripts/bussorakel \
-- emailAddress#example.com < /dev/null
alternatively, you have:
$(sh atoms.sh; sh angles.sh ) & FOR=$!
wait $FOR
mutt -s "last command done, sending email" (...)