Wrong mutt smtp server from Motion - email

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.

Related

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.

Fail to test the rendered output after a redirect from a DELETE route - Mojolicious

I currently expand my test suite to increase the test coverage. I want to test my controller and the html output that it renders, but I found a problem in using delete methods. Let me explain it in an example.
I have a route:
$r->delete('/backups/:id')
->to('backup#delete_backup')
->name('backup_delete');
that points to the following function in the backup controller:
sub delete_backup {
my $self = shift;
my $id = $self->param('id');
if ( something ) {
$self->flash( msg => "Backup id $id deleted!" );
}
else{
$self->flash( msg => "Cannot delete, backup id $id not found!" );
}
$self->redirect_to($self->url_for('backup_index'));
}
where the method that handles the route backup_index just displays the $msg and shows few other irrelevant data.
Next, I want to test this method, so I write a test:
$t_logged_in->ua->max_redirects(3);
my $page = $t_logged_in->app->url_for( 'backup_delete', id => $backup_id );
$t_logged_in->delete_ok($page)
->status_isnt( 404, "Checking: 404 $page" )
->status_isnt( 500, "Checking: 500 $page" );
The test is passed. But now, I want to check if the text is correct on the web page that is shown after redirecting. So I do the following:
$t_logged_in->ua->max_redirects(3);
my $page = $t_logged_in->app->url_for( 'backup_delete', id => $backup_id );
$t_logged_in->delete_ok($page)
->status_isnt( 404, "Checking: 404 $page" )
->status_isnt( 500, "Checking: 500 $page" )
->content_unlike(qr/Cannot delete,/i)
->content_like(qr/deleted/i);
The test fails. It fails because the content is empty, so the matching is done as there were:
'' =~ /deleted/i;
'' !~ /Cannot delete,/i;
and this is of course false in both cases. Of course, in the browser, the redirects work perfectly and I see everything as designed in the test. I can change the method to POST or GET but I wanted to make the routing properly in the way an API would be designed.
Question: how to design the test such that the content can be matched after the redirect?
For those who want to dig deeper, I give links to Github.
Routing definition line 303
Controller Backup function delete_backup line 135
Functional Test of Backup Controller line 53
Sorry no one answered this yet. I used to try to keep a closer eye on stack overflow but I got lazy :-P. This is a very interesting question.
Standard redirects (301/302) use the same verb as the original request UNLESS the original request was a POST Interestingly, this behavior was not really intended. A redirect is supposed to use the same request method as the original, but the POST->GET redirect is so commonly intended that most browsers added this behavior even though it was against the original definition. However some people really wanted a POST to remain a POST and now it depended on the implementation. In fact this got so bad that HTTP added response statuses 307/308 which always redirects as the same http verb (ie POST -> POST), even thought that was already the official behavior of the old ones but that ship had sailed. This means that POST->GET, but DELETE->DELETE is the defacto behavior of the 301/302.
This can be demonstrated in the following one liner ($_ in these one-liners is the controller):
perl -Mojo -E 'del "/delete" => sub { $_->redirect_to("/") }; any "/" => { inline => q[I got a <%= $c->req->method %>] }; app->start' get -r -v -M DELETE /delete
DELETE /delete HTTP/1.1
Host: 127.0.0.1:62690
Accept-Encoding: gzip
User-Agent: Mojolicious (Perl)
Content-Length: 0
HTTP/1.1 302 Found
Date: Sun, 18 Sep 2016 03:25:58 GMT
Server: Mojolicious (Perl)
Location: /
Content-Length: 0
DELETE / HTTP/1.1
Content-Length: 0
User-Agent: Mojolicious (Perl)
Host: 127.0.0.1:62690
Accept-Encoding: gzip
HTTP/1.1 200 OK
Content-Type: text/html;charset=UTF-8
Content-Length: 5
Date: Sun, 18 Sep 2016 03:25:58 GMT
Server: Mojolicious (Perl)
I got a DELETE
You can see that since my / route handles all methods we get a response, however the request was a DELETE. I see that in your app, you redirect to another named route whose url also handles DELETE. This is a source of your confusion as you are actually ending up there in your tests. Your redirect is effectively DELETE /backups/<<id>> -> DELETE /backups, if I'm reading your code correctly.
Now as opposed to the people who wanted to keep POST as POST, what you want here is the opposite, you want to redirect from DELETE to GET because you are trying to show a response that is not the original resource. This is the defined behavior of the little-known 303 response in which any request method is redirected to a GET. Indeed this is what early browsers should have insisted on rather than breaking the 302.
In the following example I modify the response code to 303 explicitly.
$ perl -Mojo -E 'del "/delete" => sub { $_->res->code(303); $_->redirect_to("/") }; any "/" => { inline => q[I got a <%= $c->req->method %>] }; app->start' get -r -v -M DELETE /delete
DELETE /delete HTTP/1.1
User-Agent: Mojolicious (Perl)
Host: 127.0.0.1:62716
Accept-Encoding: gzip
Content-Length: 0
HTTP/1.1 303 See Other
Location: /
Content-Length: 0
Server: Mojolicious (Perl)
Date: Sun, 18 Sep 2016 03:27:19 GMT
DELETE / HTTP/1.1
User-Agent: Mojolicious (Perl)
Accept-Encoding: gzip
Content-Length: 0
Host: 127.0.0.1:62716
HTTP/1.1 200 OK
Content-Type: text/html;charset=UTF-8
Server: Mojolicious (Perl)
Content-Length: 5
Date: Sun, 18 Sep 2016 03:27:19 GMT
I got a DELETE
But whoops, that's still a DELETE! That's because there was a bug in Mojo::UserAgent so that it didn't handle 303s correctly. I'd suggest you still make the change to your code since browsers seem to handle 303s correctly. However since Mojo::UserAgent powers Test::Mojo, your tests can't test that behavior yet. Once fixed you will see it work correctly, as my example does in my local branch:
$ perl -Ilib -Mojo -E 'del "/delete" => sub { $_->res->code(303); $_->redirect_to("/") }; any "/" => { inline => q[I got a <%= $c->req->method %>] }; app->start' get -r -v -M DELETE /delete
DELETE /delete HTTP/1.1
Content-Length: 0
User-Agent: Mojolicious (Perl)
Host: 127.0.0.1:64924
Accept-Encoding: gzip
HTTP/1.1 303 See Other
Date: Sun, 18 Sep 2016 04:59:37 GMT
Location: /
Server: Mojolicious (Perl)
Content-Length: 0
GET / HTTP/1.1
Content-Length: 0
User-Agent: Mojolicious (Perl)
Host: 127.0.0.1:64924
Accept-Encoding: gzip
HTTP/1.1 200 OK
Date: Sun, 18 Sep 2016 04:59:37 GMT
Content-Type: text/html;charset=UTF-8
Server: Mojolicious (Perl)
Content-Length: 12
I got a GET
To see more about redirect response types see https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection

How to set HTTP-headers with Perl?

I Can't set headers in Perl.
print "Expires: Thu, 08 May 2003 08:37:25 GMT\n\n";
print "Content-Type: text/html; charset=windows-1251\n\n";
print "Vary: Accept-Encoding\n\n";
First one works only. Then I have Content-Type: text/x-perl. What is wrong?
I'll assume you're using CGI to connect your web server to Perl. CGI uses a blank line to separate the headers from the response body. Since
print "Expires: Thu, 08 May 2003 08:37:25 GMT\n\n";
prints a blank line after the Expires: header, the remaining print statements are considered part of the body, not headers. You wanted:
print "Expires: Thu, 08 May 2003 08:37:25 GMT\n";
print "Content-Type: text/html; charset=windows-1251\n";
print "Vary: Accept-Encoding\n\n";

Removing metadata from Gmail sent through Email

I am using this code to send Gmail from a perl script.
use strict;
use warnings;
use Email::Send::SMTP::Gmail;
my ($mail,$error)=Email::Send::SMTP::Gmail->new( -smtp=>'smtp.gmail.com',
-login=>'xxxxxxx#gmail.com',
-pass=>'xxxxxxx');
#print "session error: $error" unless ($email!=-1);
$mail->send(-to=>'zzzzzz#gmail.com', -subject=>"Hello! there $name", -body=>'Just testing it',
-attachments=>'full_path_to_file');
$mail->bye;
This code is inside an for loop and $name is the name of intended person.
When I tested it I got some meta-data in my mail
Date: Fri, 12 Dec 2014 12:44:37 +0530
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
This doesn't happen if I use 'Hello' as -subject . The $name variable is causing this . How can I remove the metadata from the mail ?
You could be facing Image Blocking in HTML Email.