Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML Email 2

Status
Not open for further replies.

audiopro

Programmer
Joined
Apr 1, 2004
Messages
3,165
Location
GB
I am trying to send html email from a remote server.
The email is sent ok without the image html but can someone tell me if this, or a variation should work or do I need to find an alternative solution.
Code:
open( EZMAIL, "|/bin/easymail -t" ) or return 1; 
print EZMAIL "Content-Type: text/html\n";
print EZMAIL "From: welcome\@sourcename.co.uk\n";
print EZMAIL "To: cli1\@targetname.co.uk\n"; 
print EZMAIL "Subject: some subject\n\n";
print EZMAIL "<img src='[URL unfurl="true"]http://www.imagelocat.co.uk/icons/upgrade.gif'[/URL] alt='testpic'>\n";
print EZMAIL "Some content.\n";
close (EZMAIL);


Keith
 
That should send the html encoded stuff in the body of the email. The person recieving the email should see the picture if they are connected to the internet when the read the email. But you should include the proper headers for html encoded email messages.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Code:
But you should include the proper headers for html encoded email messages.
This is the problem, where do the headers go?

Keith
 
Can anyone suggest any suitable reading?
The stuff I have found so far doesn't cover what I need.
Googled for HTML header, HTML perl email, easymail HTML etc. but had no joy with anything I found useful.

Keith
 
well I use mime:lite for this stuff and my code is as follows...
Code:
##############################
###### SENDMAIL ROUTINE ######
##############################
# USING MIME::Lite;
sub send_mail {

#_[0] = To
#_[1] = From
#_[2] = Subject
#_[3] = Body Text
#_[4] = Filename
#_[5] = File
#_[6] = Type

use MIME::Lite;

my @TO = split(/\,/, $_[0]);

  foreach my $to (@TO){
    my $msg = MIME::Lite->new(  From    => "$_[1]",
                            To      => "$to",
                            Subject => "$_[2]",
                            Type    => 'multipart/mixed');

    if($_[4]){$msg->attach( Type        => "$_[6]",
                        Path        => "$_[5]",
                        Filename    => "$_[4]");
    }
 
    $msg->attach(Type        => 'TEXT/HTML',
             Data        => "$_[3]");

    $msg->send('smtp', SMTP_DOMAIN);
  }

}

there is a constant SMTP_DOMAIN defined at the top of the script and by default it is set to 127.0.0.1 , but you can make it either an IP or domain name of the SMTP server you have access to.

then the body of the email is proper HTML , so the header is dependent on what standard you are writing, just like it was a real webpage, So I'd use,
Code:
my $body = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">[/URL]
<html xmlns=\"[URL unfurl="true"]http://www.w3.org/1999/xhtml\"[/URL] xml:lang=\"en\">
<head>
    <title>Title Goes Here</title>
    <meta http-equiv=\"content-type\" content=\"application/xhtml+xml; charset=iso-8859-1\" />
    <meta name=\"author\" content=\"Your Name Here\" />
    <link href=\"[URL unfurl="true"]http://www.yourdomain.co.uk/your.css\"[/URL] rel=\"stylesheet\" type=\"text/css\" /> 
</head>
<body>
<img src='[URL unfurl="true"]http://www.imagelocat.co.uk/icons/upgrade.gif'[/URL] alt='testpic' /><br />
Some content.<br />
</body>
</html>";

my $subject = "some subject";

# send email
&send_mail("cli1\@targetname.co.uk","welcome\@sourcename.co.uk,$subject,$body);
you are trying to send an HTML email and you try to use \n which is not HTML , you use \n for plain text!

you can also pass in a string of multiple recipients which are comma separated!

I also incorporate the use of the HTML:Template module so I can write the HTML outside of PERL in correct syntax, use the Template module to merge any data with the email and then send it that way, works like a charm :-)

Hope this makes sense :-)
remember

hope this helps :-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Thanks for the reply, it was far more than I expected

I have set that up and after a few false alarms, mostly down to typos and my stupidity, I have the script running through to the end and finishing.
There are no emails being sent however.
All the vars appear correct at the start of the sub.

How should the var SMTP_DOMAIN be assigned?
Is it meant to be scalar or am I missing a very important aspect here?



Keith
 
Are you trying to use MIME::Lite? Is it installed?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
The ISP has a servercheck script listing all the modules and it says it is installed.

I would have thought it would call an error if it was not there. Is there a way of getting it to return a simple output just in case I have the wrong SMTP information set?

Keith
 
Kevin, that is MIME:Lite !!!!!

Audio,

it's up to you, I have it as a constant set at the top of the module like so...
Code:
use constant SMTP_DOMAIN => "127.0.0.1";

but you could just simply do away with the contstant and hard code it like this..

Code:
$msg->send('smtp', '127.0.0.1');

if the server running the script doesn't run SMTP for sending mail then you cannot use localhost (127.0.0.1)

simply change it to either the IP of the mail server or the domain like so
Code:
$msg->send('smtp', 'mail.myserver.com');

hope that gets it working for you :-)



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Kevin, that is MIME:Lite !!!!!

I know your code was MIMIE::Lite but the OPs original code was not coded using MIME::Lite so I asked if it was installed. Or did I misunderstand your exclamatory salutation?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
lol - no, it was just they posted saying they had got my code to work (well except for the SMTP_DOMAIN problem) and then you said use MIME::Lite.

I thought you may have missed my post and was just pointing out that the code i supplied and they were trying to use was utilising MIME:Lite.

Though I have to admit i've never heard of the module
KevinADC said:
I know your code was MIMIE::Lite
is it any good :-P

incidently not sure if you have seen my reply on the other MIME::Lite issue and 'retry' problem with Virtual SMTP in IIS.

Are you aware of anyway round this with either MIME:Lite or a different email module?

or is this a limitation with the Virtual SMTP function in IIS or indeed a configuration issue?

I understood that the IIS SMTP was outbound only , so i'm guessing its an inherent limitation that cannot be resolved with any module.

What's you thoughts on this?


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
I still cannot get it to send emails.
It appears to work because anything other than "127.0.0.1" as the SMTP var causes it to hang on the send command.




Keith
 
MIMIE::Lite

brand new module, works great. Does not need to be installed or configured in anyway. Click your heels together three times and repeat the module name and it works. Has the benefit of tranporting you over the rainbow too. [smile]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Sorry but I don't know diddly about IIS or the virtual SMTP server.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
What SMTP server do you have at your disposal?

if you are using ActiveState perl on Win with IIS and the Vertual SMTP server , is it configured?

or do you have a separate mail server you could connect to to send the mail?

i've used this module exactly as I posted it on many servers be it dedicated or shared hosting without any problem.

though are you sending email using a valid email adrress and from an email address allowed to send mail from that server?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
I will crack this as time permits.
I work on a remote server and the ISP assure me that I have the correct SMTP address. It may be a problem with something else in the script so I will go through it when I have a chance. I have seen in the docs. that the output of the module can be written to a file. I will try that to see if I can get a response from the module and take it from there.

Keith
 
no probs, I have used it in the same environment on shared hosting, and the problem I experienced was simply a case of creating a valid email address via the PLESK control panel for the address I was trying to send from.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
I went back to basics and managed to send plain text emails via the SMTP route. I have now got the emails containing an image to work but fully HTML coded emails are being trapped by spam assassin at my ISP.
Further experiments are ongoing.

Keith
 
I am making progress but have now hit a problem.
All the testing I did was in a small script containing the usual headers etc. and the following.

Code:
	my $msg = MIME::Lite->new(
	From =>'graphics@studiosoft.co.uk',
	To =>'XXXX.co.uk',
	Subject =>'HTML with in-line images!',
	Type =>'multipart/related'
	);

print "EMS1";
	$msg->attach(
	Type => 'text/html',
	Data => qq{
		<body>
		<img src='[URL unfurl="true"]http://www.XXX/emailhead.gif'[/URL] alt='testpic' /><br />
		=========================================<br>
		      Thankyou for Registering as a Service Provider<br>
		=====================================<br>
		</body>
	    },
	);
print "EMS2";	
	$msg->attach(
		Type => 'image/gif',
		Id => '[URL unfurl="true"]http://www.XXX/emailhead.gif',[/URL]
	);
	$msg->send();
print "EMS3";
I have added this to my main script as a sub routine. When I call it, an email is sent but the prog never reaches the bottom of the sub, ie. never prints EMS3.
Where am I going wrong?

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top