I've set up the mail app and created a shell script to FTP to a website server and then send an email to the admin. Last night it was working perfectly. I made changes to it this morning and it started sending two of the same email with different ASCII characters within the subject line.
#Send an email confirming update
cat /Users/rmdlp/Documents/Scripts/message.txt | mail -s “Website Update” myemail#myemail.ca
Here is a snippet of the email subject I receive:
Everything else works fine. The "message.txt" file is within the body of the message and it gets to my email OK.
Also in the sender's list this string is being added:
I also receive a "You have mail in /var/mail/$USER", which I did not receive before. I looked at that file and this is a portion of what it outputs:
Diagnostic-Code: X-Postfix; unknown user: "update???"
--9490A103F482.1450820767/Roys-MBP.lan
Content-Description: Undelivered Message
Content-Type: message/rfc822
Return-Path: <rmdlp#Roys-MBP.lan>
Received: by Roys-MBP.lan (Postfix, from userid 501)
id 9490A103F482; Tue, 22 Dec 2015 16:46:05 -0500 (EST)
To: rmdlp#live.ca, Update”#Roys-MBP.lan
Subject: “Website
Message-Id: <20151222214605.9490A103F482#Roys-MBP.lan>
Date: Tue, 22 Dec 2015 16:46:05 -0500 (EST)
From: rmdlp#Roys-MBP.lan (Roy Perez)
The command mail -s “Website Update” is not doing what you think it does. “ is U+201C, LEFT DOUBLE QUOTATION MARK, which is not the same thing as ". Unlike ", “ is not treated specially by the shell, and so the command gets split up at the whitespace in Website Update, resulting in a subject of “Website and an extra recipient of Update”. This extra recipient is interpreted as Update”#<YOUR HOSTNAME>, but because there is no such user, the email to it gets bounced back and ends up in your mailbox. All the "unknown characters" along the way are due to encoding issues.
This is why you use plain text editors to write code, not word processors.
Related
I would like to store my incoming e-mails as *.msg files and i try this with the following external delivery method; This is working well but i receive the mail as one large plain text string.
foofoofoo unix - n n - - pipe
flags=F user=www-data argv=/mle/scripts/parse_postfix.sh ${sender} ${recipient}
My parse_postfix.sh contains the following code;
#!/bin/bash
mail=$(cat);
ddate=`date +%Y%m%d_%H%M%S`
msg_file=${ddate}.msg
path=/mle/spool/${code}
echo $mail > ${path}/${msg_file};
The output of this method is one large string and i can't read it with a MIME:Parser;
(example 1)
From foo#gmail.com Sat Aug 23 19:22:27 2014 Received: from mail-yh0-f49.google.com (mail-yh0-f49.google.com [209.85.213.49]) by foo.testtesttest.com (Postfix) with ESMTPS id D83DC43C8 for <foo#testtesttest.com>; Sat, 23 Aug 2014 19:22:26 +0000 (UTC) Received: by mail-yh0-f49.google.com with SMTP id b6so9924529yha.36 for <foo#testtesttest.com>;
The example mail listed below is the way how i can read it properly with the MIME:Parser;
(example 2)
Delivered-To: foo#testtesttest.com
Received: by 10.140.108.135 with SMTP id j7csp222526qgf;
Thu, 3 Jul 2014 06:26:51 -0700 (PDT)
X-Received: by 10.194.82.106 with SMTP id h10mr3033237wjy.115.1404394010626;
Thu, 03 Jul 2014 06:26:50 -0700 (PDT)
Return-Path: <foo#gmail.com>
Received: from mail-we0-x22c.google.com (mail-we0-x22c.google.com [2a00:1450:400c:c03::22c])
by mx.google.com with ESMTPS id e6si24028130wix.75.2014.07.03.06.26.50
for <foo#testtesttest.com>
(version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
Thu, 03 Jul 2014 06:26:50 -0700 (PDT)
Received-SPF: pass (google.com: domain of foo#gmail.com designates 2a00:1450:400c:c03::22c as permitted sender) client-ip=2a00:1450:400c:c03::22c;
What is the best way to convert the 1st example to the 2nd example? Or to save the e-mail properly like the 2nd example?
You are not quoting the variable properly.
echo "$mail"
The sane solution is to not use a variable at all, though.
ddate=$(date +%Y%m%d_%H%M%S)
msg_file=${ddate}.msg
path=/mle/spool/${code}
cat> ${path}/${msg_file}
This will still be problematic if there is more than one message arriving during the same second.
I cannot see why you are not using the built-in delivery mechanisms of Postfix itself, anyway. If you want more control over delivery, maybe hook in Procmail, which has a built-in delivery mode for running numbering of messages. Proper Maildir would still be better for most real-world scenarios, as it is more robust.
I need to send a mail regarding deployment of an application using shell script.
For this I have just created a shell script and tested with
#!/bin/bash
TO_ADDRESS="to.person#domain.com"
FROM_ADDRESS="from.me#domain.com"
SUBJECT="Test mail"
BODY="hai friend, this mail is automated from shell script for Release automation."
echo ${BODY}| mail -s ${SUBJECT} ${TO_ADDRESS} -- -r ${FROM_ADDRESS}
But while running this script, it is printing like:
You have new mail in /var/spool/mail/jaykay
And a file named jaykay is created in /var/spool/mail/
Why this is happening?
How can I send a mail using shell script?
And the output file looks like
From jaykay Wed Aug 20 04:08:53 2014
Return-Path: <jaykay>
Received: (from jaykay#localhost)
by e7021.com (8.14.4/8.14.4/Submit) id s7K98rdu004168;
Wed, 20 Aug 2014 04:08:53 -0500
From: Jini K Johny <jaykay>
Message-Id: <201408200908.s7K98rdu004168#e7021.com>
Date: Wed, 20 Aug 2014 04:08:53 -0500
To: to.person#domain.com, -r, --, from.me#domain.com
Subject: Test mail
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
hai friend, this mail is automated from shell script for Release automation.
Your fundamental problem is that you must use proper quoting. This is basically a duplicate of a question which gets asked here every day.
Without quotes, the second token in $SUBJECT is interpreted as the address to send to.
An email is submitted for delivery to mail (the second word in "Test mail").
The address is undeliverable, so you get a bounce message.
The bounce message is delivered to your inbox.
Your shell notifies you that your inbox has a new message.
Additionally, it seems that your version of mail does not understand the -- option, so it gets taken as just one more address to send to. (You would get a bounce message from that, I suppose.) Because the -r option is also interpreted as just another address to send to, you get one copy (like a Bcc:) of the outgoing message in the mailbox you tried to specify in the $FROM_ADDRESS.
The fix, of course, is easy:
#!/bin/bash
TO_ADDRESS="to.person#domain.com"
FROM_ADDRESS="from.me#domain.com"
SUBJECT="Test mail"
BODY="hai friend, this mail is automated from shell script for Release automation."
echo "${BODY}" | mail -s "${SUBJECT}" "${TO_ADDRESS}" # -- -r "${FROM_ADDRESS}"
(The curlies aren't really necessary here, but I kept them since you had them in your code.)
E.g. this recent answer has guidance for when and how exactly you need to quote.
The mail program is really a rather thin wrapper; you could do something like this instead;
/usr/lib/sendmail -oi -t -f "$FROM_ADDRESS" <<____HERE
From: My Name <$FROM_ADDRESS>
To: Your Name <$TO_ADDRESS>
Subject: $SUBJECT
$BODY
____HERE
... where the path to /usr/lib/sendmail is likely to be something else on many systems.
(For bonus k00lness points, add X-Mailer: Look, I can put anything I like here!)
I'm guessing here that you meant sendmail -f "$FROM_ADDRESS" which sets the envelope sender address (not -r which I cannot find documented anywhere).
Why this email adress desp#mariacamorales.com is generating an exception.
`check_response': 550 5.1.1 <desp#mariacamorales.com>... User unknown (Net::SMTPFatalError)
The original script is
# encoding: utf-8
require 'mail'
require 'active_support/time'
today = Date.today
year, month, day = today.to_s.split("-")
subject = "Backup base de datos #{ today }"
to = ["desp#mariacamorales.com"]
mail = Mail.new(subject: subject, body: subject, from: "backup#mydomain.com", to: to)
mail.add_file "/home/project/backups/data/#{ year }/#{ month }/#{ today }-sada.bz2"
mail.deliver!
The script works fine with other emails adresses.
The 550 error is a response from the SMTP server you are connecting to. The server must have the mariacamorales.com domain configured as local and the user desp does not exist there.
mail defaults to sending via localhost so you will probably have a qmail, postfix, sendmail or exim process dealing with SMTP. These would normally default to the hosting email the suffix of the hostname of the machine (host.domain.com). Each can have domains configured independently of the hostname of the machine.
If you are not sure where to start, sudo grep -ir mariacamorales.com /etc might point to what you need.
I would like to know how to close an APPEND command from the Unix Terminal. My goal is to create a Draft message on the Gmail IMAP server from the Mac Terminal or with JavaME. I've used the follow commands so far:
openssl s_client -crlf -connect imap.gmail.com:993
...
A1 LOGIN myaccount#gmail.com mypassword
...
A2 SELECT "[Gmail]/Drafts"
...
A3 APPEND "[Gmail]/Drafts" (\Seen) {310}
+ go ahead
Date: Fri, 29 Apr 2011 10:00:00 -0800 (PST)
...
Content-Type: TEXT-PLAIN; CHARSET=US-ASCII
Message Body
I tried to send a CRLF (\r\n) by using a socket connection and the Control+V, return, return in the Terminal.
{310} is the exactly number of message characters, including the carriage return and line feed, it worked fine.
For testing purposes I want send mail to my localhost user account rather than my webserver. I am unsure how to do this using mail.app. Any help would be appreciated.
#Tautologistics
OSX does have a built-in MTA (SMTP server), to turn it on you can type:
sudo launchctl start org.postfix.master
then you can send mail to localhost like you desire
sample showing an SMTP server running from my machine running 10.6.1
>telnet 127.0.0.1 25
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
>sudo launchctl start org.postfix.master
>telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 machinename.example.com ESMTP Postfix
If you don't specifically want to use Mail.app, you can send mail using the mail command. Open Terminal and:
mail -s "Testing" `whoami`#`hostname`
<type something>
Ctrl-D to finish and send
Those are backticks, not single quotes. whoami returns the current user's username and hostname returns the local machine's hostname. It could also be explicit:
mail -s "Testing" john#mymac.local
EDIT: Just read your clarification. Mail.app stores it's data in ~/Mail, mostly in an SQLite database (the 'Envenlope Index' file). The tables of interest would be mailboxes and messages. The text of the email is stored in individual files in the respective mailbox/folder directories. This would probably be the way to go, if you want to access email that has been fetched by Mail.app (in realtime).
Yet another option would be to export your mail from the Mail.app using the mbox format and access it using the technique described by dbr. Depending on whether or not realtime access is desired, you might be able to script something up that automates the export.
I'm looking to login into my (local) mail server, access a mailbox, and do some parsing. So, I assume there's a mail server running locally but not sure how to access it
The local mail isn't stored in a POP3/IMAP server, but rather using a UNIX'y mbox. A file stored in /var/mail/ (the file-name is the users login)
For example..
$ mail dbr
Subject: hi
test
^d # ctrl+d (EOF)
$ cat /var/mail/dbr
From dbr#parabola.local Tue Dec 30 13:43:57 2008
Return-Path: <dbr#parabola.local>
X-Original-To: dbr
Delivered-To: dbr#parabola.local
Received: by parabola.local (Postfix, from userid 501)
id 4FEA1158E36; Tue, 30 Dec 2008 13:43:57 +1030 (CST)
To: dbr#parabola.local
Subject: hi
Message-Id: <20081230031357.4FEA1158E36#parabola.local>
Date: Tue, 30 Dec 2008 13:43:57 +1030 (CST)
From: dbr#parabola.local (dbr)
test
Not sure about Ruby (I had a search around, but couldn't find anything, although there is undoubtably a module for this), but I know Python has a maildir.mbox module, which would use in the following way:
>>> msgs = mailbox.mbox("/var/mail/dbr")
>>> for msg in msgs:
... print "Subject:", msg['subject']
...
Subject: hi
Unless you are running OSX Server, then there's no SMTP/IMAP/POP3 server running locally. You can get one up and running very easily using Post Fix Enabler or, if you don't mind the command line, use MacPorts to install postfix:
sudo port install postfix
Send mail from localhost LocalhostMail is a simple and fast solution for Mac OS X that lets you send email messages from your PHP-application (or any other, located on localhost) by Mail.app included with Mac OS X. If you use PHP, just add to MySQL database new messages, and our application will send them through a Mail application. LocalhostMail uses your mail account in Mail.app to send these messages, so you do not need a separate SMTP-server for your localhost.localhostmail.com
codelogic,
thanks, I did know about sending mail from the terminal. I think my question was not well thought out. I'm looking to login into my (local) mail server, access a mailbox, and do some parsing. So, I assume there's a mail server running locally but not sure how to access it.
I'm using ruby:
pop = Net::POP3.new 'macbook.local'
pop.start 'me', 'mypass'
but get a Timeout::Error: execution expired