首页 > 解决方案 > 在 PL/SQL 中将电子邮件中的文本加粗

问题描述

在以电子邮件粗体发送之前,我试图在变量 var_sub_title 粗体中格式化文本。

  declare
  var_sub_title varchar2(60);
  var_txt varchar2(500);
  var_msg_sub varchar2(60);
  
  begin
  select sub_title, txt, subject into var_sub_title, var_txt, var_msg_sub from table where msg_id = :id;
     -- SEND EMAIL --
  HTMLDB_MAIL.SEND(
       P_to   => 'email@mail.com',
       p_from =>'email@email.net',
       p_body => var_sub_title||CHR(10)||CHR(13)||var_txt||CHR(10)||CHR(13);                
       p_subj => var_msg_sub); 
   htmldb_mail.push_queue;
  end;

我怎样才能归档这个?

标签: htmlsqlplsql

解决方案


As documentation says, you need to pass your HTML-formatted text to parameter p_body_html, not p_body:

Plain text and HTML e-mail content. Passing a value to p_body, but not p_body_html results in a plain text message. Passing a value to p_body and p_body_html yields a multi-part message that includes both plain text and HTML content.

So your code should be:

declare
  var_sub_title varchar2(60);
  var_txt varchar2(500);
  var_msg_sub varchar2(60);
  
  begin
  select sub_title, txt, subject into var_sub_title, var_txt, var_msg_sub from table where msg_id = :id;
     -- SEND EMAIL --
  HTMLDB_MAIL.SEND(
       P_to        => 'email@mail.com',
       p_from      => 'email@email.net',
       p_body_html => '<b>'|| var_sub_title || '</b>' || CHR(10) || CHR(13) || var_txt || CHR(10) || CHR(13);                
       p_subj      => var_msg_sub); 
   htmldb_mail.push_queue;
  end;

Also there are other restrictions on length and ability to process HTML emails by recipient's email client.

When using HTMLDB_MAIL.SEND, remember the following:

  • No single line may exceed 1000 characters. The SMTP/MIME specification dictates that no single line shall exceed 1000 characters. To comply with this restriction, you must add a carriage return or line feed characters to break up your p_body or p_body_html parameters into chunks of 1000 characters or less. Failing to do so will result in erroneous e-mail messages, including partial messages or messages with extraneous exclamation points.
  • Plain text and HTML e-mail content. Passing a value to p_body, but not p_body_html results in a plain text message. Passing a value to p_body and p_body_html yields a multi-part message that includes both plain text and HTML content. The settings and capabilities of the recipient's email client determine what displays. Although most modern e-mail clients can read a HTML formatted email, remember that some users disable this functionality to address security issues.
  • Avoid images. When referencing images in p_body_html using the tag, remember that the images must be accessible to the recipient's e-mail client in order for them to see the image

推荐阅读