Hello experts,
This is my second post to the forum and need expert help.
I have the following Stored procedure that fetches data from a database and uses the UTL_SMTP package and sends mail. However, for some reason I want it to go through all recipents from the table and fire off an email to all the recipients in the table. You can see what I mean by the code below.
CREATE OR REPLACE PROCEDURE InfoCollection
IS
cursor get_data is
Select * from Table_X;
v_data get_data%ROWTYPE;
mailhost VARCHAR2(30) := 'mailhost';
mail_conn utl_smtp.connection;
message varchar2(2000);
BEGIN
open get_data;
Loop
fetch get_data into v_data;
END LOOP
close get_data;
message := 'Hello '||v_data.D_Name||',<BR>
<BR>
You can find your information at the following URL:<BR><BR>'||
'<a href='||v_data.r_link||'>'||v_data.r_link||'</a>';
mail_conn := utl_smtp.open_connection(mailhost, 25);
UTL_SMTP.HELO(mail_conn, mailhost);
UTL_SMTP.MAIL(mail_conn, 'xxx@XXX.XXX');
UTL_SMTP.RCPT(mail_conn, v_data.d_email);
utl_smtp.rcpt(mail_conn, v_data.v_email);
utl_smtp.data(mail_conn, 'SUBJECT: Link to info'||utl_tcp.crlf||
'Content-Type: text/html;'||utl_tcp.crlf||message);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
UTL_SMTP.QUIT(mail_conn);
raise_application_error(-20000, 'Failed to send mail due to the following error: ' || sqlerrm);
END;
So, looking at the code it should send mail to d_email and v_email. It should then loop through the rest of the rows(data) in the table and do the same for all d_email and v_email fields. It is not doing this. I currently have 2 rows in the table with 4 email address. 2 for d_email(both different) and 2 for v-email(both different). It is only firing off to 1 email address. Any ideas. Using oracle 9.
I have removed the real mailhost and email address for security reasons. Thanks.
This is my second post to the forum and need expert help.
I have the following Stored procedure that fetches data from a database and uses the UTL_SMTP package and sends mail. However, for some reason I want it to go through all recipents from the table and fire off an email to all the recipients in the table. You can see what I mean by the code below.
CREATE OR REPLACE PROCEDURE InfoCollection
IS
cursor get_data is
Select * from Table_X;
v_data get_data%ROWTYPE;
mailhost VARCHAR2(30) := 'mailhost';
mail_conn utl_smtp.connection;
message varchar2(2000);
BEGIN
open get_data;
Loop
fetch get_data into v_data;
END LOOP
close get_data;
message := 'Hello '||v_data.D_Name||',<BR>
<BR>
You can find your information at the following URL:<BR><BR>'||
'<a href='||v_data.r_link||'>'||v_data.r_link||'</a>';
mail_conn := utl_smtp.open_connection(mailhost, 25);
UTL_SMTP.HELO(mail_conn, mailhost);
UTL_SMTP.MAIL(mail_conn, 'xxx@XXX.XXX');
UTL_SMTP.RCPT(mail_conn, v_data.d_email);
utl_smtp.rcpt(mail_conn, v_data.v_email);
utl_smtp.data(mail_conn, 'SUBJECT: Link to info'||utl_tcp.crlf||
'Content-Type: text/html;'||utl_tcp.crlf||message);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
UTL_SMTP.QUIT(mail_conn);
raise_application_error(-20000, 'Failed to send mail due to the following error: ' || sqlerrm);
END;
So, looking at the code it should send mail to d_email and v_email. It should then loop through the rest of the rows(data) in the table and do the same for all d_email and v_email fields. It is not doing this. I currently have 2 rows in the table with 4 email address. 2 for d_email(both different) and 2 for v-email(both different). It is only firing off to 1 email address. Any ideas. Using oracle 9.
I have removed the real mailhost and email address for security reasons. Thanks.