MySQL Forums
Forum List  »  Triggers

Re: Send email via trigger
Posted by: Adrian Hondema
Date: March 07, 2009 05:11AM

I have to say: your solution works like a treat!. I only added some error-handling as I discovered that at some times the mail.eml file still exists in de pickup directory. So, I added this line: DECLARE EXIT HANDLER FOR 1083 SET FileExists = 1; I make sure that the status of the E-mail in my database table is not changed to 'transmitted' where the error-condition occurs. As a result, the E-mail will be adressed again during the next event. Thanks for getting me in the right direction! My Event looks like this:

DELIMITER $$

create event ev_zend_email on schedule every 10 second
do
begin
DECLARE FileExists INT DEFAULT 0;

-- Email
DECLARE Volgnr BIGINT;
DECLARE Dossiernr BIGINT;
DECLARE Aan CHAR(150);
DECLARE Cc CHAR(150);
DECLARE Bcc CHAR(150);
DECLARE Onderwerp CHAR(150);
DECLARE Body TEXT;

DECLARE cur1 CURSOR FOR SELECT email_volgnr,
email_to,
email_cc,
email_bcc,
email_titel,
email_tekst
FROM dossier_emails
WHERE email_verzonden_op is null limit 1;

OPEN cur1;

FETCH cur1 INTO Dossiernr, Volgnr, Aan, Cc, Bcc, Onderwerp, Body;

if aan <> "" then
BEGIN
DECLARE EXIT HANDLER FOR 1083 SET FileExists = 1;

SELECT concat("To: ", Aan),
"From: emailserver@mysqlevent.nl",
concat("Subject: ", Onderwerp),
"",
"Er wordt een aktie van u verwacht. De specificatie van deze aktie treft u hieronder aan:",
"",
concat("Gewenste aktie: ", body),
"",
"Disclaimer: The contents of this email and any attachments are confidential and exclusively intended for the named recipient(s). If you are not the intended recipient, you are requested not to use the contents and to notify the sender immediately. In that case, you are also requested to destroy this email and any attachments. Although the information has been compiled with great care, ProcesVolgSysteem does not guarantee the proper and complete transmission of the information contained in this email nor for any delay in its receipt."
INTO OUTFILE "/inetpub/mailroot/pickup/mail.eml"
FIELDS TERMINATED by '\r\n';

UPDATE dossier_emails set email_verzonden_op = current_timestamp where email_volgnr = Volgnr;
END;

end if;

CLOSE cur1;

END $$

DELIMITER ;

Options: ReplyQuote


Subject
Views
Written By
Posted
69755
July 09, 2005 09:24AM
35543
July 09, 2005 04:00PM
23107
July 10, 2005 07:18AM
34831
October 19, 2005 08:53AM
27979
October 20, 2005 09:40AM
24374
October 23, 2005 05:16AM
15523
February 13, 2007 06:35AM
15134
May 13, 2007 10:39AM
11564
November 24, 2008 11:10PM
14429
February 22, 2007 03:44AM
12724
December 08, 2007 08:17AM
10248
September 09, 2008 04:00AM
8942
March 12, 2009 07:08AM
18987
February 27, 2007 07:53AM
9741
September 09, 2008 04:02AM
12709
May 14, 2007 01:07AM
11915
June 04, 2007 01:14PM
11006
June 27, 2007 10:10PM
10352
August 09, 2007 06:15AM
12723
August 25, 2007 09:13AM
13158
August 30, 2007 01:24AM
16526
August 30, 2007 11:43PM
31899
September 12, 2007 05:39AM
11555
December 08, 2007 03:25AM
8942
December 08, 2007 05:19AM
7705
August 04, 2008 01:15AM
7249
January 12, 2009 05:10AM
7218
January 07, 2009 04:37AM
Re: Send email via trigger
10508
March 07, 2009 05:11AM
6937
March 12, 2009 06:21AM
8410
March 12, 2009 06:38AM
15862
April 16, 2009 05:53PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.