2017-08-12 92 views
0

我有此過程發送電子郵件。我想知道除了電子郵件地址之外,還有什麼方法可以添加顯示名稱的發件人嗎?使用帶發送者姓名的oracle發送電子郵件

我附上了工作代碼。問題是不添加發件人名稱。

p_smtp_host := '192.xxx.xxx.xxx'; 
    p_smtp_port := 25; 

    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); 
    process_recipients(l_mail_conn, p_to); 
    process_recipients(l_mail_conn, p_cc); 
    process_recipients(l_mail_conn, p_bcc); 

    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); 

    IF TRIM(p_cc) IS NOT NULL THEN 
    UTL_SMTP.write_data(l_mail_conn, 'CC: ' || REPLACE(p_cc, ',', ';') || UTL_TCP.crlf); 
    END IF; 

    IF TRIM(p_bcc) IS NOT NULL THEN 
    UTL_SMTP.write_data(l_mail_conn, 'BCC: ' || REPLACE(p_bcc, ',', ';') || UTL_TCP.crlf); 
    END IF; 

    UTL_SMTP.write_data(l_mail_conn, 'From: ' || p_from || 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_text_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/plain; charset="iso-8859-1"' || UTL_TCP.crlf || UTL_TCP.crlf); 

    UTL_SMTP.write_data(l_mail_conn, p_text_msg); 
    UTL_SMTP.write_data(l_mail_conn, UTL_TCP.crlf || UTL_TCP.crlf); 
    END IF; 

    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); 

回答

1

提供這樣

FromName := 'Wernfried Domscheit'; 
FromMail := '[email protected]'; 
UTL_SMTP.WRITE_DATA(l_mail_conn, 'From: "'||FromName||'" <'||FromMail||'>'||UTL_TCP.CRLF); 

郵件請注意,默認SMTP支持From場只有ASCII字符,如果你的名字可能包含非ASCII字符(例如,「彼得·穆勒)你應該這樣寫:

IF REGEXP_LIKE(FromName, '^[ -~]+$') THEN 
    UTL_SMTP.WRITE_DATA(l_mail_conn, 'From: "'||FromName||'" <'||FromMail||'>'||UTL_TCP.CRLF); 
ELSE 
    UTL_SMTP.WRITE_DATA(l_mail_conn, 'From: =?UTF-8?B?'|| UTL_ENCODE.TEXT_ENCODE(FromName, NULL, UTL_ENCODE.BASE64) ||'?= <'||FromMail||'>'||UTL_TCP.CRLF); 
END IF;