Unix: How to send Mime files as mails - email

I have a program that outputs MIME formatted files. I need to send these from an unix machine.
The files have the format as such:
From: ******
To: ******
Message-ID: ******
Subject: ******
MIME-Version: ******
Content-Type: ******
Content-Transfer-Encoding: ******
<PAYLOAD>
Is there a way to specify such a file (Preferably without specifying any other information than the file) through a native unix command, such as sendmail?

Related

How to read MIME file

I need some help to download email attachments from S3 bucket, email formats are MIME files. How can I read this email file and download attachment? Any good source is appreciated too
Content-Type: application/octet-stream;
name="3c1bd1393c7543cd9f38c1ff26d474ab.snappy.parquet"
Content-Disposition: attachment;
filename="3c1bd1393c7543cd9f38c1ff26d474ab.snappy.parquet"
Content-Transfer-Encoding: base64
Content-ID: <f_l6z42itv0>
X-Attachment-Id: f_l6z42itv0

in Perl sendmail, why is my Image attachment becoming corrupt, sometimes?

I intend to rewrite this in Net::SMTP but right now i need a backup subroutine that doesn't "use" much, so;
The code works and sends emails, when received in most email service (Godaddy,ProtonMail) i get the full image, but in another (34SP) email service i only get the top half of the image.
my $msg = "From: John <$sender>
To: bob <$recipient>
Subject: $subject
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=\"BOUNDARY\"
--BOUNDARY
Content-Type: multipart/alternative; boundary=\"MSGBOUNDARY\"
--MSGBOUNDARY
Content-Type: text/html; charset=iso-8859-1
Content-Disposition: inline
<html><body>Hello, World<br><img src=\"cid:hello\"></body></html>
--MSGBOUNDARY
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Hello, World,[you're missing an image here]
--MSGBOUNDARY--
--BOUNDARY
Content-Type: image/jpeg
Content-Disposition: inline; filename=\"hello.jpg\"
Content-Transfer-Encoding: base64
Content-Id: <hello>
$jpgg
--BOUNDARY--";
open MAIL, "| $sendmail -t"
or die "Couldn't pipe to $sendmail";
print MAIL $msg;
close MAIL;
I've tested the 34SP email service by sending this first attachment from another location and it receives it fine, so it must be a problem with the code. If anyone can see something I've done wrong, I'd appreciate it.
EDIT(1); as per Polar Bears suggestion I've edited the code for easier reading, I've tested this version and am still getting the same issue.
Just a suggestion to change the code to following form
my $msg = "
From: John <$sender>
To: bob <$recipient>
Subject: $subject
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=\"BOUNDARY\"
--BOUNDARY
Content-Type: multipart/alternative; boundary=\"MSGBOUNDARY\"
--MSGBOUNDARY
Content-Type: text/html; charset=iso-8859-1
Content-Disposition: inline
<html><body>Hello, World<br><img src=\"cid:hello\"></body></html>
--MSGBOUNDARY
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Hello, World,[you're missing an image here]
--MSGBOUNDARY--
--BOUNDARY
Content-Type: image/jpeg
Content-Disposition: inline; filename=\"hello.jpg\"
Content-Transfer-Encoding: base64
Content-Id: <hello>
$jpgg
--BOUNDARY--
";
open MAIL, "| $sendmail -t"
or die "Couldn't pipe to $sendmail";
print MAIL $msg;
close MAIL;

Wrong mutt smtp server from Motion

I'm using Motion to manage a camera and it works perfectly.
I've configured mutt so it can send emails when an event occur on the camera.
When I send an email via mutt by myself it works every times.
But when it's motion that send the email, the "from:" field is not good and it doesn't send the email. Do you know why ? I've configured my ~/.muttrc file and it works when I do it without motion.
my ~/.muttrc :
# Name of expeditor
set realname = "Camera"
# Activate TLS if available on the server
set ssl_starttls=yes
# Always use SSL for connection to the server
set ssl_force_tls=yes
# Configuration of imap (Only if you want to be able to read emails on the Pi)
#set spoolfile=imaps://imap.gmail.com:993/
#set imap_user = "XXXXXXXX#gmail.com"
#set imap_pass = "PASSWORD"
# Configuration SMTP
set smtp_url = "smtp://[MY_EMAIL]#smtp.gmail.com:587/"
set smtp_pass = "[MY_PASSWD]"
set from = "[MY_EMAIL]"
set use_envelope_from=yes
# Local info, date
#set locale="fr_FR"
set date_format="%A %d %b %Y à %H:%M:%S (%Z)"
#set locale="iso-8859-15"
Normal "sent" file (when I do it without Motion) :
From john.smith#gmail.com Wed May 2 07:28:59 2018
Date: Wed, 2 May 2018 07:28:59 +0000
From: =?iso-8859-1?Q?Camera <john.smith#gmail.com>
To: john.smith#gmail.com
Subject: Test
Message-ID: <20180502072859.qhqyhfwcs5nw7quj#RPi>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: NeoMutt/20170113 (1.7.2)
Status: RO
Content-Length: 2
Lines: 1
Wrong "sent" file (when I do it with Motion) :
From motion#RPi Wed May 2 07:17:07 2018
Date: Wed, 2 May 2018 07:17:07 +0000
From: motion#RPi
To: john.smith#gmail.com
Subject: Picture
Message-ID: <20180502071707.nx7asct4m2hds6vt#RPi>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: NeoMutt/20170113 (1.7.2)
Status: RO
Content-Length: 39
Lines: 1
Can you help me ?
Thank you very much
A.

Email Attachments w/ base64 Encoding on Rhat

I am migrating from an old HP-UX box to a new Rhat box. Our ERP emailer program saves the email (including MIME headers) as "Email_msg_port.html" and the attachment in the user's home dir. No problem so far.
The emailer then issues the following command:
(cat Email_msg_8.html ; base64 /home/johnsmith/APMS9010.txt) | sendmail -t
The email itself is fine, but the attachment is always empty (though it says it is about 300 bytes).
My MIME header looks like this:
MIME-Version: 1.1
From: myEmail#myCompany.com
To: myEmail#myCompany.com
Subject: APMS9010.1 - Download Top Vendor Purchase - LIVE.DATA
Content-Type: multipart/mixed; boundary="_boundarystring"
This is a multi-part message in MIME format.
--_boundarystring
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: binary
Content-Disposition: inline
Content-Base: "http://myCompany.com/";
I have tried Content-Transfer-Encoding: binary (and 7bit)
Is my MIME stuff wrong, the base64 command wrong, both, or something else?
Thanks

mime-type missing in mailsend email client

I'm using "mailsend v.1.19" to text a webmail client.
When I set mime-type, whether is with message body or one line message, I cannot find any trace of it into the raw email.
e,g:
mailsend -smtp local-mail.com -f sender#sender.local -t receiver#receiver.local -sub "Another Test Email With HTML body and mime type set from file body" -msg-body ~/justbody.html -starttls -user xxx -pass xxxx -mime-type "text/html"
I'm deliberately not setting content-type for testing purposes.
My SMPT ingestor will get the following raw stream with no signs of "text-html":
Received: from localhost (unknown [10.91.142.1])
by local-mail.dev.com (Postfix) with ESMTPS
for receiver#receiver.local; Wed, 31 Jan 2018 11:37:10 +0000 (UTC)
Subject: Another Test Email With HTML body and mime type set from file body
From: sender#sender.local
Date: Wed, 31 Jan 2018 11:37:10 +0000
To: receiver#receiver.local
X-Mailer: #(#) mailsend v1.19 (Unix)
X-Copyright: BSD. It is illegal to use this software for Spamming
Mime-version: 1.0
Content-Type: (null); charset=utf-8
What am I getting wrong?
I have tried using mailsend with both parameters -content-type and mime-type both placed before the message body in the command line.
The result is that the header Content-type is filled with mime-type value.
So when mime-type is set, content-type header contains its value, when both are set, content-type still takes the mime-type parameter value and ignores the content-type.
I believe this issue is related to mailsend clean in documentation what is the logic behind it.