0
在我的項目中,要求從數據庫(Oracle)發送HTML電子郵件(通知)。我正在使用UTL_SMTP實用程序。但是,通知模板需要存儲在其中一個數據庫列中,每個通知模板都包含HTML文本和變量。來自oracle數據庫的HTML電子郵件
請在下面找到UTL_SMTP代碼:
CREATE OR REPLACE FUNCTION Email_Temp(
p_to IN NVARCHAR2,
p_subject IN NVARCHAR2,
p_template_id IN Form_Templates.template_id%type)
RETURN NVARCHAR2
AS
Ret_String NVARCHAR2(10);
p_from NVARCHAR2 (2000) := 'This is fixed(Database server)';
p_smtp_host NVARCHAR2 (2000) := 'Database';
p_smtp_port NUMBER := 25;
p_html_msg NVARCHAR2 (4000) := NULL;
l_mail_conn UTL_SMTP.connection;
l_boundary NVARCHAR2 (50) := '----=*#abc1234321cba#*=';
BEGIN
l_mail_conn := UTL_SMTP.open_connection (p_smtp_host, p_smtp_port);
UTL_SMTP.helo (l_mail_conn, p_smtp_host);
UTL_SMTP.mail (l_mail_conn, p_from);
UTL_SMTP.rcpt (l_mail_conn, p_to);
UTL_SMTP.open_data (l_mail_conn);
UTL_SMTP.write_data (l_mail_conn, 'From: ' || p_from || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, 'Sent: ' || TO_CHAR (SYSDATE,'FMDay, FMMonthDD, YYYY HH12:MI:SS PM') || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, 'To: ' || p_to || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, 'Subject: ' || p_subject || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, 'Reply-To: ' || p_from || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, 'MIME-Version: 1.0' || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn
, 'Content-Type: multipart/alternative; boundary="' || l_boundary || '"' || UTL_TCP.crlf
|| UTL_TCP.crlf
);
IF p_html_msg IS NOT NULL
THEN
select html_string into p_html_msg from Form_Templates where template_id = p_template_id;
UTL_SMTP.write_data (l_mail_conn, '--' || l_boundary || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, 'Content-Type: text/html; charset="iso-8859-1"' || UTL_TCP.crlf || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, p_html_msg);
UTL_SMTP.write_data (l_mail_conn, UTL_TCP.crlf || UTL_TCP.crlf);
END IF;
UTL_SMTP.write_data (l_mail_conn, '--' || l_boundary || '--' || UTL_TCP.crlf);
UTL_SMTP.close_data (l_mail_conn);
UTL_SMTP.quit (l_mail_conn);
Ret_String := 'Sucess';
RETURN Ret_String;
END;
/
現在,它們將被存儲在數據庫中的字段(固定的文本和變量)每個模板看起來像下面的示例:
<html>
<body>
<h4 style="color:blue;">Assignee Notification</h4><br>
Hello Assignee,
<br><br>
You have been assigned a document.
<br><br>
<font size="3" color="blue"><b>Project Name:</b></font> variable
<br>
<font size="3" color="blue"><b>Document Nickname: </b></font> variable
<br><br>
</body>
</html>
我需要調用郵件函數的模板,但同時,模板應該包含固定文本和帶有值的變量。
你的解決方案是沒用的,你沒有提供代碼(或任何其他來源)的包'MAIL_PKG'。 –
@WernfriedDomscheit OP不詢問如何發送電子郵件。他們問如何修改電子郵件中的模板。 – kevinsky