Removing metadata from Gmail sent through Email - perl

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.

Related

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.

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.

Email Sent By Perl (Net::SMTP) Script Dropped Silently by Gmail

I have a Perl script that sends simple HTML emails to users with status updates and a link to more information. I'm creating mail with Net::SMTP and sending mail using smtp-relay.gmail.com. It has been working great for years.
In the last month, the emails stopped appearing - just gone with no errors and not in SPAM. Hours of troubleshooting later, I've narrowed the problem down to Gmail silently dropping emails that contain my specific URL.
http://DOMAIN/cgi-bin/requests/single_request.pl?requestid=111111
I changed one character and POOF! working again.
http://DOMAIN/cgi-bin/requests/single-request.pl?requestid=111111
I know this is a vague question, but what is going on? The workaround is fine, but I sure didn't learn anything about the root cause.
#!c:\strawberry\perl\bin -w
use strict;
use warnings;
use Net::SMTP;
use Net::Config;
# use this function to send email
#
# example:
#
# send_mail("RECIPIENT\#DOMAIN", "SUBJECT HERE", "BODY HERE");
sub send_mail{
my $recipient = shift;
my $subject = shift;
my $body = shift;
# connect to an SMTP server
my $smtp = Net::SMTP->new("smtp-relay.gmail.com", Debug => 0, Timeout => 30, Hello => 'REDACTED') or die "SMTP Connection Failed: smtp-relay.gmail.com";
# sender's address here
$smtp->mail('REDACTED');
# recipient"s address
$smtp->to($recipient);
# Start the mail
$smtp->data();
# Send the header.
$smtp->datasend("MIME-Version: 1.0\n");
$smtp->datasend("Content-Type: text/html; charset=\"UTF-8\" \n");
$smtp->datasend("To: $recipient . \n");
$smtp->datasend("From: REDACTED\n");
$smtp->datasend("Reply-to: REDACTED\n");
$smtp->datasend("Subject: $subject \n");
$smtp->datasend("\n");
# Send the body.
$smtp->datasend($body);
# Finish sending the mail
$smtp->dataend();
# Close the SMTP connection
$smtp->quit();
}
1;

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";

How do I get the output of WWW:Curl::Easy into a variable in Perl

use WWW::Curl::Easy;
$curl->setopt(CURLOPT_HEADER,1);
$curl->setopt(CURLOPT_RETURNTRANSFER,1);
$curl->setopt(CURLOPT_URL,"http://example.com/login.php");
$curl->setopt(CURLOPT_POSTFIELDS,"user=usertest&pass=passwdtest");
$curl->perform();
It will printout like this.
How do I get the output into a variable from perform function?
HTTP/1.1 302 Found Cache-Control:
no-cache, must-revalidate Expires:
Sat, 11 Jan 200 05:00:00 GMT
Location: ?cookiecheck=1
Content-type: text/html Date: Thu, 28
Apr 2011 09:15:57 GMT Server:
xxxx/0.1 Content-Length: 0
Connection: Keep-Alive Set-Cookie:
auth=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
expires=Sat, 27-Apr-2013 09:15:57 GMT;
path=/; domain=.example.com
I agree with PacoRG that you most likely should look into using a module from the LWP:: space. Since you have more specific needs I would recommend the LWP::UserAgent.
That said if you really need to get something which is being printed to instead be stored in a variable, we can play some games with deeper Perl magic.
# setopt method calls here
## the variable you want to store your data in
my $variable;
{
## open a "filehandle" to that variable
open my $output, '>', \$variable;
## then redirect STDOUT (where stuff goes when it is printed) to the filehandle $output
local *STDOUT = $output;
## when you do the perform action, the results should be stored in your variable
$curl->perform();
}
## since you redirected with a 'local' command, STDOUT is restored outside the block
## since $output was opened lexically (with my), its filehandle is closed when the block ends
# do stuff with $variable here
Perhaps WWW::Curl::Easy has a better way of doing this, since I don't know that module's commands I have provided you with a hack that will do what you need.
What are you trying to do? May be LWP::Simple is what you need...
Over 11 years later, I hope this helps:
my $response;
sub write_data($$$$) {
$response = shift;
return length($response);
}
# ... curl setup
$curl->setopt(CURLOPT_WRITEFUNCTION,\&write_data);
# ... curl perform
print "$response\n"