Solved

Sending .eml files to postfix

Posted on 2011-02-11
3
1,408 Views
Last Modified: 2013-12-18
I have a postfix mail server setup that is currently sending/receiving mail just fine.  We want to set up a folder on the postfix box for an application to write/transfer .eml files to to get mailed out.  Is there a way to tell postfix to grab the files from that folder or a way to take the files from that folder and forward them to postfix so that they get mailed?
0
Comment
Question by:swagers
3 Comments
 
LVL 12

Expert Comment

by:nxnw
Comment Utility
You may be able to do it with the mail command in a shell script invoked periodically by launchd.

See man mail in terminal.
0
 

Author Comment

by:swagers
Comment Utility
Looked through the mail manual didn't see a way to send the .eml file as the actual message.  Also I should mention that the postfix server is running two instances of postfix, as its sending and signing mail for two seperate domains, so it would also be helpful to be able to specify which instance of postfix that the .eml file is being sent to.
0
 
LVL 26

Accepted Solution

by:
skullnobrains earned 500 total points
Comment Utility
eml files do not preserve envelope information

you may write a simple shell script to parse the headers and send the mail to postfix using a simple netcat if you believe you can trust the to and from headers

this is a sample you should be able to adapt to your needs

file=$1
rcpt=`sed -n 's/To:.*<\([^<>]*\)>.*/\1/p'`
test -n $rcpt || rcpt=`sed -n 's/To:[[:space:]]*\([^[:space:]]*\)[[:space:]]*/\1/p'`

{
echo 'helo local_eml_sender'
echo 'mail from: <>'
echo 'rcpt to: <$rcpt>'
echo data
cat $file | sed 's/^./../'
echo -e "\r\n.\r\n"
sleep 5
} | nc localhost 25 | grep queued\ as \
&& rm $file

you can work without  the sleep hack if you use freebsd which has a proper nc implementation

you can build a much better email sender with netpipes but you probably would use a more convenient programing language then

good luck

ps script would be launched using find and xargs so you spawn it once per file.
something like this :
find $eml_directory -type f -name \*.eml | xargs -n1 -p 10 path/to/script
would run 10 parallel instances of the script
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This is about my first experience with programming Arduino.
Resolve DNS query failed errors for Exchange
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now