Gossamer Forum
Home : General : Perl Programming :

Sending file by email blues :(

(Page 2 of 2)
> >
Quote Reply
Re: [Andy] Sending file by email blues :( In reply to
oops
Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
Thanks. That all looks fine. Are you sure its not working in Thunderbird? Works fine in Gmail for me. You could try also sending to support@educationusingpowerpoint.co.uk, as I use Outlook for that (and thats more fussy)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sending file by email blues :( In reply to
i'm certain it doesn't work in thunderbird; i have latest version. i sent one to your other address.
Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
Mmm yeah doesn't work for me in Outlook either. Can you send me the exact code you are using? (via email). Just the bit around the attachments - ideally as an attachment. and I'll play with it my end and see if I can spot whats going on

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sending file by email blues :( In reply to
i just installed an add-on for thunderbird called show all body parts. now the messages show attachments at the bottom for the text part of message as well as the attachment. i've noticed in the past that some emails i receive look like this but don't know why. also, this add on is advertised to be obsolete when version 72 of thunderbird comes out.
i will email the code.
Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
Hi,

Its probably a rogue newline somewhere - as it came out like the attached for me in Outlook

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sending file by email blues :( In reply to
sorry, i don't understand. where would the rogue newline be?
Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
this is crazy!!! suddenly it isn't sending email at all. it just comes back to the form instead of the success page!
Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
I'm still playing with it. Seems some email clients want it with sub-part sections (different "section ids"). Just trying to work out how to do this as I can't find any documentation around it

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sending file by email blues :( In reply to
looking over my code, i was wondering where do i tell it my mail program and smtp server? also, can i add several things to header like:
Code:
my $email = Email::MIME->create(

header_str => [
From => $from,
To => [ $to ],
Return-Path => $admin_email,
Bcc => $bcc,
Cc => $cc,
Reply-To => $reply_to,
Subject => $subject,
],
parts => \@parts,
attributes => {
encoding => 'base64',
charset => "UTF-8",
content_type => "multipart/alternative",
disposition => "inline",
}
);

why is $to enclosed in brackets?
Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
Hi,

To send with SMTP you want to use Email::Sender::Transport::SMTP:

Code:
my $transport = Email::Sender::Transport::SMTP->new({
host => 'smtp.gmail.com',
port => 465,
ssl => 1,
sasl_username => 'smtpusername',
sasl_password => 'smtp pass'
});

Then the sendmail() call looks like:

Code:
sendmail($email->as_string, { transport => $transport } );

If you want to send BCC, you have to do it like:

Code:
sendmail($email->as_string, { transport => $transport, to => [$to, $bcc] } );

I tried it before with just headers, but they were ignored and no CC/BCC's were sent out

I'm still playing with the attachment stuff. Basically, the issue is the structure of the email. It has to send like:

Code:
multipart/mixed
|- multipart/alternative << mail client will choose which of the parts to display
| | text/plain << the mail as plain text
| | text/html << the mail as HTML
|- text/plain << the attachment

But is instead sending all the parts with 1 boundary ID:

Code:
multipart/mixed
|- multipart/alternative << mail client will choose which of the parts to display
| | text/plain << the mail as plain text
| | text/html << the mail as HTML
|- text/plain << the attachment

Its weird - because when I was writing this email code before, it all worked fine in the tests! So looks like its not been behaving properly in some email clients for a while :(

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
Man that was a pain - but got there in the end! This is a working function I now have:

Code:

use Email::MIME;
use Email::Address::XS;
use Email::Sender::Simple qw(sendmail);
use IO::All;
use GT::MIMETypes;

my $to = 'support@foo.co.uk'; #$rec{'Email'};

my $from = $admin_email;
my $subject = "some title";
my $html = "some test <b>message</b> foo bar test";
my $text = "some test message some plain version";
$html = decode( 'utf-8', $html );
$text = decode( 'utf-8', $text );

# multipart message
my @message_parts = (
Email::MIME->create(
body_str => $text,
attributes => {
encoding => 'quoted-printable',
content_type => "text/plain",
disposition => "inline",
charset => "UTF-8",
}
),
Email::MIME->create(
body_str => $html,
attributes => {
encoding => 'quoted-printable',
charset => "UTF-8",
content_type => "text/html",
disposition => "inline",
}
)
);


my @all_parts;
push @all_parts, Email::MIME->create(
parts => \@message_parts, # add all the message parts into here...
attributes => {
content_type => "multipart/alternative"
}
);

my $attach = "/home/user/web/foo.co.uk/public_html/cgi-bin/admin/tables.cgi";

if ($attach) {

my $filename = (reverse split /\//, $attach)[0]; # also changed in body => below

# better to use GT::MIMETypes if you have it with Fileman (pretty sure you do?)
my $mime = GT::MIMETypes::guess_type($filename);

push @all_parts, Email::MIME->create(
attributes => {
filename => $filename,
content_type => $mime,
encoding => "base64",
name => $filename
},
body => io( $attach )->binary->all,
)
}


my $email = Email::MIME->create(
header_str => [
From => $from,
To => [ $to ],
Subject => $subject
],
parts => \@all_parts,
attributes => {
encoding => 'base64',
content_type => "multipart/mixed"
}
);

print qq|Structure: | . $email->debug_structure. "\n\n";


sendmail($email->as_string);

The important part is that you create one set of "parts" for the plain and html text. Then another for the attachments.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sending file by email blues :( In reply to
Andy wrote:
Hi, To send with SMTP you want to use Email::Sender::Transport::SMTP:
Code:
my $transport = Email::Sender::Transport::SMTP->new({
host => 'smtp.gmail.com',
port => 465, ssl => 1,
sasl_username => 'smtpusername',
sasl_password => 'smtp pass' });

Then the sendmail() call looks like:
Code:
sendmail($email->as_string, { transport => $transport } );
how was it sending before??? remember, i was able to send, but the attachments were inconsistent on PC vs. mobile. i haven't changed anything to do with my smtp setting!

also, can i omit the $html section? the email form takes plain text so i'm not sending anything with html tags.
Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
Hi,

If you didn't specify SMTP stuff, it would have just been sending via Sendmail.

To just use plain text emails - change:

Code:
# multipart message
my @message_parts = (
Email::MIME->create(
body_str => $text,
attributes => {
encoding => 'quoted-printable',
content_type => "text/plain",
disposition => "inline",
charset => "UTF-8",
}
),
Email::MIME->create(
body_str => $html,
attributes => {
encoding => 'quoted-printable',
charset => "UTF-8",
content_type => "text/html",
disposition => "inline",
}
)
);


my @all_parts;
push @all_parts, Email::MIME->create(
parts => \@message_parts, # add all the message parts into here...
attributes => {
content_type => "multipart/alternative"
}
);

To:

Code:
# multipart message
my @message_parts = (

Email::MIME->create(
body_str => $text,
attributes => {
encoding => 'quoted-printable',
content_type => "text/plain",
disposition => "inline",
charset => "UTF-8",
}
)
);

my @all_parts;
push @all_parts, Email::MIME->create(
Email::MIME->create(
parts => \@message_parts, # add all the message parts into here...
attributes => {
encoding => 'quoted-printable',
content_type => "text/plain",
disposition => "inline",
charset => "UTF-8",
}
),
);

If the emails are getting through ok though, you may not even need to use SMTP (its only really if you are worried about DKIM/SDF/DPAC rules blocking your emails coming through, if you have them set up to filter traffic not coming from your SMTP server's IP)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Mar 20, 2020, 5:18 AM
Quote Reply
Re: [Andy] Sending file by email blues :( In reply to
the emails are not sending at all now. Frown i have no idea why they sent yesterday morning and then quit.

when i was using the old print MAIL statements i had line:
Code:
open (MAIL, "$mailprog") || &cgierr("unable to open mail program");

do i need something like that now?
Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
What does your full code look like now?

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sending file by email blues :( In reply to
sub attached. i have a global.pl that has
Code:
$mailprog = "|/usr/lib/sendmail -t";


$smtp_server="mymailserver";



(has actual server instead of mymailserver Wink)
Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
Hi,

Just before:

Code:
my $bcc = '';

Can you add:

Code:
print "Content-type: text/html \n\n";
print "MESSAGE SENDING ". $email->as_string . "\n";

Then when you run it, can you copy the top 20 lines of the output? I want to see if the headers look correct (mainly the "To" and "From")

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sending file by email blues :( In reply to
nothing happened because it wasn't getting to that line. i figured out why! i had
Code:
my ($status,$attach,$newfile);

if ($in{'Filename'}) {
($status,$attach) = &get_email_attachment;
}
if ($status ne 'ok') {
$message .= $status;
&html_send_email_form($message);
return;
}

if i didn't have an attachment, $status was blank so it was returning to the form without a message. so i changed to

Code:
my $status = 'ok';
my ($attach,$newfile);
if ($in{'Filename'}) {
($status,$attach) = &get_email_attachment;
}
if ($status ne 'ok') {
$message .= $status;
&html_send_email_form($message);
return;
}
and it is sorta handling text and attachments in both desktop and mobile. mobile is perfect, but desktop text area of message looks like this:
Code:
sending a document
NBA_PICKS.xlsx
PK!A7n[Content_Types].xml ( Tn0W?DV[$xX$(}'fQU%Ql[&<&YB@l.YO$` r=HEV5  ӵLb.j""%5
3NB?C%*=YK)ub8xR-JWQ23V$sU.)PI ]h:C@im2
desktop email has link to attachment like it's supposed to.

when i sent a text only message it also had a line between the text and then two lines with double-digit numbers.


Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
Hi,

Can you send me the full outputted email via email? (headers, body etc)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
> >