command to email file as an attachment - email-attachments

I'm using the following command to send an email with a specific file attached from the web server to me
mail -A /home/root/BACKUPS/backup.sql -s "$(date +%F) sql Backup" me#domain.com < /dev/null
Resource: https://tecadmin.net/ways-to-send-email-from-linux-command-line/
Problem is that although it is sending me an email, it's not attaching the item (backup.sql).
Does anyone see the problem with this code? Or is there something else that needs to be done to make the code work?

Related

Mails are not sent using mutt on command line

I tried to send e-mails using mutt on commande line
echo "File encoding finished on $Now_dmY, with some errors ffmpeg: $ffmpeg MP4Box: $mp4box Thumb: $thumb Rsync: $rsync" | mutt -s "[Failed] Encoding File" -- foo#bar.com
The result is:
/root/sent is not a mailbox.
Could not send the message.
You have mail in /var/mail/root
When I opened the root file:
Diagnostic-Code: smtp; 530 5.7.1 Client was not authenticated
--A1DA321EB7.1563969927/ns366860.ip-94-23-8.eu
Content-Description: Undelivered Message
Content-Type: message/rfc822
Thank you
We had the same issue with the "sent" file.
Turned out that the file permissions somehow "changed" from 600 to 611 and that inhibited the operation.
We renamed the file so mutt would create a new file and it worked fine and that's had we figured out that the permissions changed.
We would never had though to try that if not for the info above!
Thanks everyone on this site!
Try adding -e 'unset record' to your mutt command.
It's similar question to Mutt failing as cron job with 'Couldn't lock /sent'
I preferred adding unset record at the end of .muttrc configuration file.

mail: Invalid header when sending mail attachment with Ubuntu

This exact question was posted by user 'anvd' on 29th July but then removed - I found it on Google Cached version...!
I'm guessing the fix was something obvious, but would be great if it wasn't removed.
I am trying this command to send an email with an attachment.
echo 'These are contents of my daily backup' | mail -s 'Daily backup' -a /tmp/filename.gz mymail#hotmail.com
The error: mail: Invalid header: /tmp/filename.gz
The email gets sent, but the attachment is not attached.
This used to work, and still dos on other systems, but not sure what has changed on one of my machines...
I just had this problem. It turns out that -a is the flag for appending headers, whereas -A is the flag for attaching files.

Telegram CLI unread messages

I want to display unread messages with telegram cli running on my raspberry pi, and save them to some file which will be processed later with php, and displayed on a small TFT screen.
I think it may be possible with get_dialog_list () but I can't find a way to make it work.
Any help/advice is welcome! :-)
If you choose php as a laguage to write your customized client or just pull messages from Telegram, you need to connect to the tg client and then send or receive messages.
You can easily wirte a Bash script and use it inside your php code.
#!/bin/bash
now=$(date)
from=$1
subject=$2
body=$3
tgpath=/home/telpath/tg
LOGFILE="/home/logpath/tglog.log"
cd ${tgpath}
${tgpath}/telegram -k ${tgpath}/tg-server.pub -W <<EOF
msg $to $subject
safe_quit
EOF
echo "$now Recipient=$from " >> ${LOGFILE}
echo "Finished" >> ${LOGFILE}
So we will have:
<?php
while (TRUE) {
$output = shell_exec('tg.sh', '#user');
echo "<pre>$output</pre>";
}
?>
You can easily iterate over your bash script (tg.sh) to pull messages from any contact.
Note that these codes are trivial like a sudo code and needs more development.

Sending an one-message email to a receiver by batch script file(windows)

Actually i am writing batch file to validate a text file formats. "sending an email by using lotus note" is used for reporting to receiver that any format goes right or wrong. "Sending an email" is an action after reaching if-statements.
code for sending email:
I am referencing to how can I add body to the mailto link from console Win?
if %number% equ %count% (
start "" "mailto:username in lotus note?subject=subject&body=body "
)
I am almost there, the code above start lotus note and filled in the subject&body automatically.But it don't hit the "send" button,i have to write batch script for this send action,any suggestion
Oh, i got the answer by referencing to How to send an email from one Gmail account to another one using a batch file or script?.
First, download blat from http://www.blat.net/ on the left hand side, then you will get blat.exe after unzip some download packages. Then, blat.exe should be included in the same directory of your batch file. This sendmail action allow sender to use a fake email address and in the command i show you should put down your organization or company server name & port number(generally 25).
Finally, an email can be sent by using code below:
blat.exe - -f anyAddress#mail.com -to recipient#mail.com -s Subject -body "type you body here" ^ -server hp2-server.abcd.abcdef:25
pause
some notification like "Sending stdin.txt to bla bla bla" will be shown on command windows once it succeeds.

fetchmail/procmailrc filter by date

I have fetchmail grab my email from a pop account and send it to procmail. I have 'keep' set in my fetchmailrc file because i also use the email for outlook and i cant have fetchmail taking all my emails.
My problem is i want to download just todays emails or at lease since last time fetchmail ran.
right now i am trying to filter by date in the procmail file but it is not working.
I am using fedora14
contents of .procmailrc
SHELL=/bin/bash
DATEZ="date +'%a, %d %m %Y'"
:0
*^From.*\<(blah#blah\.com|blah2#blah2\.ca)\>
*^Content-Type:*
*^ name.*\.(xls|doc)
*$ ^Date:.*$DATEZ
{
:0fw
| uudeview -p $HOME/Inbound/Received -
:0
| $HOME/Inbound/Start.bash 2> /dev/null
}
Well it pays to read. In the fetchmail manual it explains in detail to use the -U flag. This then only downloads the emails from when you last polled the server.
so the command is:
fetchmail -k -U