tags:

views:

31

answers:

2

i am new in trigers working.how to send email by using trigers in mysql?

A: 

I've never used triggers, but this link could help.

http://www.datasprings.com/Resources/ArticlesInformation/CreatingEmailTriggersinSQLServer2005.aspx

Phil
question is about MYSQL, not SQLSERVER...
Tim Coker
i have already use this code in my examle but when trigger is run then it give me the follwing error which is belong to this line "INTO OUTFILE "/inetpub/mailroot/pickup/mail.eml"" is give this error "#1 - Can't create/write to file '\inetpub\mailroot\pickup\mail.eml' (Errcode: 2) "
Rana Azeem
A: 

First, why do you need to do this. If you are using PHP, ASP.NET, JSP, etc... it may be easier to put this functionality in that code.

Otherwise use MySQL's SELECT INTO OUTFILE functionality.

EXAMPLE:

CREATE TRIGGER send_emailverifier AFTER INSERT, UPDATE ON tbl_users
FOR EACH ROW BEGIN
SELECT * FROM email_bodies WHERE EmailID = 1;
SELECT * FROM tbl_users WHERE ClientID = @ClientID
INSERT INTO tbl_emailverify VALUES (UUID, tbl_users.ClientID, OLD.CltEmail, NEW.CltEmail)
SELECT concat("To: ",NEW.CltEmail & "," & OLD.CltEmail),
               "From: [email protected]",
               concat("Subject: ",NEW.subject),
               "",
               email_bodies.EmailContent
INTO OUTFILE "/inetpub/mailroot/pickup/mail.eml"
FIELDS TERMINATED BY '\r\n';
# END

If not on Windows then the /inetpub/mailroot/pickup/mail.eml folder path would need to be changed for your platform.

If using the mailroot/pickup folder save to a temp folder first to ensure the file is completed before being emailed.

Or you could post the contents to a PHP (or ASP, JSP, etc...) page that will email it for you.

Todd Moses
i have already use this code in my examle but when trigger is run then it give me the follwing error which is belong to this line
Rana Azeem