Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

html - Making text bold in an email in PL/SQL

I am trying to format text in the variable var_sub_title bold before sending it in email bold.

  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 protected]',
       p_from =>'[email protected]',
       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;

how can i archiev this?

question from:https://stackoverflow.com/questions/66045321/making-text-bold-in-an-email-in-pl-sql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 protected]',
       p_from      => '[email protected]',
       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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...