UTL_SMTP.WRITE_DATA 修剪电子邮件正文中的多余空格 |甲骨文

问题描述 投票:0回答:1

Oracle Database 19c 企业版版本 19.0.0.0.0 - 生产 版本19.20.0.0.0

我正在使用 UTL_SMTP 发送电子邮件。下面是代码

declare
 l_mail_conn   UTL_SMTP.connection;
  l_boundary    VARCHAR2(50) := '              =abc1234321cba=';
  p_smtp_host VARCHAR2 (100) := 'smtp.cac.com';
   p_smtp_port      NUMBER := 25;
   p_to VARCHAR2(100) := '[email protected]';
   p_subject VARCHAR2(100) := 'Hello';
   p_html_msg  VARCHAR2(100) :=  '              ' ||'ABC <br>' || '              ' || 'DEF';
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_to);
  UTL_SMTP.rcpt(l_mail_conn, p_to);

  UTL_SMTP.open_data(l_mail_conn);
  
  UTL_SMTP.write_data(l_mail_conn, 'Date: ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') || UTL_TCP.crlf);
  UTL_SMTP.write_data(l_mail_conn, 'To: ' || p_to || UTL_TCP.crlf);
  UTL_SMTP.write_data(l_mail_conn, 'From: ' || 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, '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
    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);
END;
/

我能够收到电子邮件,但电子邮件正文正在修剪重复的空格,无论它们是前导还是尾随

上面代码的输出是

预期输出为

请观察预期输出中突出显示的前导空格。我无法理解这段代码出了什么问题。

感谢您的阅读,感谢任何帮助。

oracle
1个回答
0
投票

这与 Oracle 无关,而是与 html 有关。尝试设置

   p_html_msg  VARCHAR2(100) :=  '<pre>' || '              ' ||'ABC <br>' || '              ' || 'DEF';

p_html_msg  VARCHAR2(100) :=  '&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp' ||'ABC <br>' || '&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp' || 'DEF';

https://blog.hubspot.com/website/html-space

© www.soinside.com 2019 - 2024. All rights reserved.