Gossamer Forum
Home : Products : Links 2.0 : Customization :

Include txt for newsletter?

Quote Reply
Include txt for newsletter?
Hi,

Is it possible to include text from a seperate file into each email sent as a newsletter?

Such as adding html from data.txt into an email sent to bob@bob.com?


Quote Reply
Re: Include txt for newsletter? In reply to
This is possible but will take some work. The script to modify is nph-email.cgi, sub main. Look for this code, which is the area you would need to work in:
Code:
# If from newsletter, we go through the form input, and mail to each user.
foreach $address (@address) {
At this point, you would have to include code to check and see if the address matches the email address you want to include additional information for. If so, you open the file, and read the information into the $message variable, something like this:
Code:
if ($address eq "bob\@bob.com") {
OPEN (FILE "</path/to/data.txt") or &cgierr("Can't open data.txt, reason: $!");
while (<FILE>) {
$message .= $_;
}
CLOSE FILE;
}
You might need a series of these if there are multiple addresses you want to include additional information for. If the same data.txt file would be used for all of the "selected" addressees (but not "all" addressees), you could modify the if statement above to include them, such as:
Code:
if ($address =~ "bob\@bob.com|jim\@jim.com|bill\@bill.com") {
I hope this helps.

- Bobsie
bobsie@orphanage.com
http://goodstuff.orphanage.com/
Quote Reply
Re: Include txt for newsletter? In reply to
Thanks a lot Bobsie,

That should do the trick. How about emailing everyone in your mailing list the contents of that data.txt file?

I wouldnt be using "If" statements otherwise right?

Thanks.

Quote Reply
Re: Include txt for newsletter? In reply to
You wouldn't do any of that at all if everyone was to get the same data.txt file. Instead, you would just include the information in the message by modifying sub html_mail_update, admin_html.pl by putting what you want between the <textarea> ... </textarea> HTML tags.

You don't need a separate data.txt file to do that.

- Bobsie
bobsie@orphanage.com
http://goodstuff.orphanage.com/
Quote Reply
Re: Include txt for newsletter? In reply to
Hi Bobsie,

Actually the file that I would include to all recipients, is dynamically created. So, the contents of it is changing everyday.

Having said that, would the code you supplied work now, taking away the IF statement?

Thanks a lot. :)

Quote Reply
Re: Include txt for newsletter? In reply to
Go into admin_html.pl, sub html_mail_update and, after this line:

my $subject = "What's new for " . &get_date;

add this code:
Code:
my $mydata = "";

OPEN (FILE "</path/to/data.txt") or &cgierr("Can't open data.txt, reason: $!");
while (<FILE>) {
$mydata .= $_;
}
CLOSE FILE;
Next, find this code:
Code:
<textarea name=message rows=40 cols=50>
Somewhere between that code and the </textarea> tag, insert $mydata; the exact placement is up to you. Be sure you change /path/to/data.txt to the correct path to your data file.

Now you can update the data.txt file anytime and it will be included in your message when it goes out.

Is that what you want?

- Bobsie
bobsie@orphanage.com
http://goodstuff.orphanage.com/
Quote Reply
Re: Include txt for newsletter? In reply to
Yes it is,

Thanks a lot Bobsie...
:)

Quote Reply
Re: Include txt for newsletter? In reply to
Actually,

I was planning to use the Cron mailing CGI taht Tggr created some days back. So the modification has to be in here somehwere right:

sub main{ my $message = &build_new_links . $cfg_mail_footer; my $subscribers = &build_email_list; my $subject = $cfg_title; my $start = time(); print qq|Mailing started on |, scalar localtime($start), "\n";# Make sure we have everything we need. my %seen; $message =~ s/\r//g; $message or (print "No message defined! Aborting!" and exit); $subject or (print "No subject defined! Aborting!" and exit); $db_admin_email or (print "An admin email has not been set in the config. Aborting!" and exit); ($db_smtp_server or $db_mail_path) or (print "No SMTP server or Sendmail has been defiend in the config. Aborting!" and exit);# Let's initilize a mailer. my $mailer = new Mailer ( { smtp => $db_smtp_server, sendmail => $db_mail_path, from => $db_admin_email, subject => $subject, msg => $message, log => $db_mailer_log } ) or &cgierr("Unable to init mailer! Reeason: $Mailer::error"); print qq~Mailing Message:--------------------------------------------------------From: $db_admin_emailSubject: $subject$message--------------------------------------------------------~;



Thanks, that code was taken from the post
http://gossamer-threads.com/perl/forum/showthreaded.pl?Cat=&Board=L2Cust&Number=85060&Search=true&Forum=L2Cust&Words=cron email&Match=And&Searchpage=0&Limit=25&Old=allposts