Re: lfcr with plpgsql - Mailing list pgsql-novice
From | Derrick Betts |
---|---|
Subject | Re: lfcr with plpgsql |
Date | |
Msg-id | 1c7901c5244c$ae6c1340$0200a8c0@main Whole thread Raw |
In response to | lfcr with plpgsql ("Derrick Betts" <derrick@grifflink.com>) |
Responses |
Re: lfcr with plpgsql
|
List | pgsql-novice |
This is the line that sends the mail in the function in question: PERFORM pgmail(\'Reminders@EvergreenMortgageInc.com\',email_1,\'Reminder Notice\',Body,\'text/html\'); where the email_1 variable is the TO: address. The Body variable is as explained below. This is the pgmail function: CREATE OR REPLACE FUNCTION pgmail(text, text, text, text, text) RETURNS int4 AS ' set mailfrom $1 set mailto $2 set mailsubject $3 set mailmessage $4 set contenttype $5 set myHost "127.0.0.1" set myPort 25 set mySock [socket $myHost $myPort] set toemailaddress_start [string first "<" $mailto] if {$toemailaddress_start != -1} { set toemailaddress_finish [string first ">" $mailto] set toemailaddress_start [expr $toemailaddress_start + 1] set toemailaddress_finish [expr $toemailaddress_finish - 1] set toemailaddress [string range $mailto $toemailaddress_start $toemailaddress_finish] } else { set toemailaddress $mailto } set fromemailaddress_start [string first "<" $mailfrom] if {$fromemailaddress_start != -1} { set fromemailaddress_finish [string first ">" $mailfrom] set fromemailaddress_start [expr $fromemailaddress_start + 1] set fromemailaddress_finish [expr $fromemailaddress_finish - 1] set fromemailaddress [string range $mailfrom $fromemailaddress_start $fromemailaddress_finish] } else { set fromemailaddress $mailfrom } fileevent $mySock writable [list svcHandler $mySock] fconfigure $mySock -buffering none puts $mySock "HELO 127.0.0.1" gets $mySock name puts $mySock "mail from: $fromemailaddress" gets $mySock name puts $mySock "rcpt to: $toemailaddress" gets $mySock name puts $mySock "data" gets $mySock name puts $mySock "To: $mailto" puts $mySock "From: $mailfrom" puts $mySock "Content-Type: $contenttype" puts $mySock "Subject: $mailsubject" puts $mySock "" puts $mySock "$mailmessage" puts $mySock "." gets $mySock name close $mySock return 1' LANGUAGE 'pltclu' VOLATILE; Thanks, Derrick ----- Original Message ----- From: "Michael Fuhr" <mike@fuhr.org> To: "Derrick Betts" <derrick@grifflink.com> Cc: <pgsql-novice@postgresql.org> Sent: Tuesday, March 08, 2005 5:42 PM Subject: Re: [NOVICE] lfcr with plpgsql > On Tue, Mar 08, 2005 at 03:12:23PM -0700, Derrick Betts wrote: > >> It doesn't seem to be working that way, however. This is the code that >> writes the string: >> >> Body := \'Hello \'||agentnm||\',\n\'; >> Body := Body || \'This is a reminder for you to make contact with >> \'||fname||\' \'||lname||\'.\n\'; >> Body := Body || \'The time to make contact was \'||remtime||\'\n\n\'; >> Body := Body || \'Thanks,\n\'; >> Body := Body || \'The reminder system\'; >> >> And this is the result in the email that I receive: >> >> Hello Derrick Betts, This is a reminder for you to make contact with Tom >> Jones. The time to make contact was 2005-03-09 13:25:00 Thanks, The >> reminder system > > How are you sending and reading the mail? I pasted your code into > a PL/pgSQL function that calls a PL/Perl function that sends email, > and it worked in my mail reader (i.e., the received message had > line breaks where the original message had \n characters). > > Could you post a simple but complete example? Something we could > copy into an empty database that would duplicate your results. > > -- > Michael Fuhr > http://www.fuhr.org/~mfuhr/ > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org >
pgsql-novice by date: