oops
Mar 19, 2020, 5:46 AM
Veteran / Moderator (18441 posts)
Mar 19, 2020, 5:46 AM
Post #27 of 45
Views: 7359
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!
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!
Mar 19, 2020, 5:57 AM
Veteran / Moderator (18441 posts)
Mar 19, 2020, 5:57 AM
Post #29 of 45
Views: 7359
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!
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!
Mar 19, 2020, 6:04 AM
Enthusiast (661 posts)
Mar 19, 2020, 6:04 AM
Post #30 of 45
Views: 7360
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.
i will email the code.
Mar 19, 2020, 6:08 AM
Veteran / Moderator (18441 posts)
Mar 19, 2020, 6:08 AM
Post #31 of 45
Views: 7355
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!
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!
Mar 19, 2020, 8:45 AM
Veteran / Moderator (18441 posts)
Mar 19, 2020, 8:45 AM
Post #34 of 45
Views: 7350
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!
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!
Mar 19, 2020, 10:21 AM
Enthusiast (661 posts)
Mar 19, 2020, 10:21 AM
Post #35 of 45
Views: 7347
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:
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?
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?
Mar 20, 2020, 12:06 AM
Veteran / Moderator (18441 posts)
Mar 20, 2020, 12:06 AM
Post #36 of 45
Views: 7338
Hi,
To send with SMTP you want to use Email::Sender::Transport::SMTP:
host => 'smtp.gmail.com',
port => 465,
ssl => 1,
sasl_username => 'smtpusername',
sasl_password => 'smtp pass'
});
Then the sendmail() call looks like:
If you want to send BCC, you have to do it like:
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:
|- 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:
|- 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!
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!
Mar 20, 2020, 2:01 AM
Veteran / Moderator (18441 posts)
Mar 20, 2020, 2:01 AM
Post #37 of 45
Views: 7331
Man that was a pain - but got there in the end! This is a working function I now have:
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!
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!
Mar 20, 2020, 3:23 AM
Enthusiast (661 posts)
Mar 20, 2020, 3:23 AM
Post #38 of 45
Views: 7328
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 } );also, can i omit the $html section? the email form takes plain text so i'm not sending anything with html tags.
Mar 20, 2020, 3:38 AM
Veteran / Moderator (18441 posts)
Mar 20, 2020, 3:38 AM
Post #39 of 45
Views: 7330
Hi,
If you didn't specify SMTP stuff, it would have just been sending via Sendmail.
To just use plain text emails - change:
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:
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!
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!
Mar 20, 2020, 3:43 AM
Enthusiast (661 posts)
Mar 20, 2020, 3:43 AM
Post #40 of 45
Views: 7333
the emails are not sending at all now. i have no idea why they sent yesterday morning and then quit.
when i was using the old print MAIL statements i had line:
do i need something like that now?
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?
Mar 20, 2020, 3:45 AM
Veteran / Moderator (18441 posts)
Mar 20, 2020, 3:45 AM
Post #41 of 45
Views: 7326
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!
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!
Mar 20, 2020, 4:10 AM
Veteran / Moderator (18441 posts)
Mar 20, 2020, 4:10 AM
Post #43 of 45
Views: 7325
Hi,
Just before:
Can you add:
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!
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!
Mar 20, 2020, 4:29 AM
Enthusiast (661 posts)
Mar 20, 2020, 4:29 AM
Post #44 of 45
Views: 7330
nothing happened because it wasn't getting to that line. i figured out why! i had
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
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:
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@im2desktop 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.
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;
}
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
when i sent a text only message it also had a line between the text and then two lines with double-digit numbers.
Mar 20, 2020, 4:34 AM
Veteran / Moderator (18441 posts)
Mar 20, 2020, 4:34 AM
Post #45 of 45
Views: 7321
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!
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!