2012-03-05 6 views
3

私はこの画像を電子メールに埋め込む際にStackOverflowのgreat question and answerを見ました。残念ながら、回答者は電子メールを境界線で分割する方法については説明していませんでした。境界線の内容が分からないと答えました。境界を使用して、マルチパート/関連MIMEタイプの電子メールを分割するにはどうすればよいですか?

これは私が試したものです:

v_body := '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15"> 
    </head> 
    <body bgcolor="#ffffff" text="#000000"> 
    <img src="data:image/jpg;base64,------------090303020209010600070908' || v_image || '------------090303020209010600070908" /> 
    </body> 
</html>'; 

utl_mail.send('myemail.example.com', 
       'myemail.example.com', 
       null, 
       null, 
       'Image attachment test', 
       v_body, 
       'multipart/related; boundary="------------090303020209010600070908"', 
       null); 

ではなく画像に変換する生の文字としてbase64文字列を送信します。

その後、私が試した:

v_body := 'This is a multi-part message in MIME format. 
--------------090303020209010600070908 
Content-Type: text/html; charset=ISO-8859-15 
Content-Transfer-Encoding: 7bit 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
    <head> 

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15"> 
    </head> 
    <body bgcolor="#ffffff" text="#000000"> 
    <img src="cid:part1.06090408.01060107" alt=""> 
    </body> 
</html> 

--------------090303020209010600070908 
Content-Type: image/png; 
name="moz-screenshot.png" 
Content-Transfer-Encoding: base64 
Content-ID: <part1.06090408.01060107> 
Content-Disposition: inline; 
filename="moz-screenshot.png" 

' || v_image || ' 

--------------090303020209010600070908-- '; 

utl_mail.send('myemail.example.com', 
       'myemail.example.com', 
       null, 
       null, 
       'Image attachment test', 
       v_body, 
       'multipart/related; boundary="------------090303020209010600070908"', 
       null); 

電子メールの内容は、この時間は表示されませんでした。

Oracleの境界を使用して、マルチパート/関連MIMEタイプの電子メールを分割するにはどうすればよいですか。私はパッケージUTL_SMTP使用している

+1

[This](http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:255615160805)は役に立つかもしれません – vijayaragavan

+1

[This](http:// www.oracle-base.com/articles/misc/EmailFromOraclePLSQL.php#attachment)も面白いかもしれません。 – Eggi

答えて

1

procedure send_email (
    p_image blob 
    ) 
    is 
    conn utl_smtp.connection; 
    BOUNDARY VARCHAR2 (256) := '-----090303020209010600070908'; 
    i   pls_integer; 
    len  pls_integer; 
    buff_size pls_integer := 57; 
    l_raw  raw(57); 
    begin

conn := UTL_SMTP.open_connection (smtp_host, smtp_port); UTL_SMTP.helo (conn, smtp_domain); UTL_SMTP.mail (conn, '[email protected]'); UTL_SMTP.rcpt (conn, '[email protected]'); UTL_SMTP.open_data (conn); UTL_SMTP.write_data (conn, 'From' || ': ' || '[email protected]'|| UTL_TCP.CRLF); UTL_SMTP.write_data (conn, 'To' || ': ' || '[email protected]'|| UTL_TCP.CRLF); UTL_SMTP.write_data (conn, 'MIME-Version: 1.0' || CHR (13) || CHR (10)); UTL_SMTP.write_data (conn, 'Content-Transfer-Encoding: 8bit' || CHR (13) || CHR (10)); UTL_SMTP.write_data (conn, 'Subject: image in attachment' || CHR (13) || CHR (10)) ; UTL_SMTP.write_data (conn, 'Content-Type: multipart/mixed; boundary="' || BOUNDARY || '"' || UTL_TCP.CRLF); UTL_SMTP.write_data (conn, 'X-Mailer:Mailer by Oracle UTL_SMTP'); UTL_SMTP.write_data (conn, UTL_TCP.CRLF); UTL_SMTP.write_data (conn, 'This is a multi-part message in MIME format.' || UTL_TCP.crlf); UTL_SMTP.write_data (conn, '--' || BOUNDARY || UTL_TCP.CRLF); UTL_SMTP.write_data (conn, 'Content-Type: text/html; charset="windows-1251"'|| UTL_TCP.CRLF); UTL_SMTP.write_data (conn, UTL_TCP.CRLF); UTL_SMTP.write_data (conn, 'put your html code here'); UTL_SMTP.write_data (conn, UTL_TCP.CRLF); UTL_SMTP.write_data (conn, '--' || BOUNDARY || UTL_TCP.CRLF); UTL_SMTP.write_data (conn, 'Content-Type: image/jpeg;'|| UTL_TCP.CRLF); UTL_SMTP.write_data (conn, 'Content-Disposition: inline; filename="image.jpg"' || UTL_TCP.CRLF); UTL_SMTP.write_data (conn, 'Content-Transfer-Encoding' || ': ' || 'base64' || UTL_TCP.CRLF); UTL_SMTP.write_data (conn, 'Content-ID: <part1.06090408.01060107>'); UTL_SMTP.write_data (conn, UTL_TCP.CRLF); UTL_SMTP.write_data (conn, UTL_TCP.CRLF); i := 1; len := dbms_lob.getlength(p_image); while i < len loop dbms_lob.read(p_image, buff_size, i, l_raw); utl_smtp.write_raw_data(conn, utl_encode.base64_encode(l_raw)); utl_smtp.write_data(conn, utl_tcp.crlf); i := i + buff_size; end loop; utl_smtp.write_data(conn, utl_tcp.crlf); UTL_SMTP.write_data (conn, '--' || BOUNDARY || '--' || UTL_TCP.CRLF); UTL_SMTP.write_data (conn, UTL_TCP.CRLF); UTL_SMTP.close_data (conn); UTL_SMTP.quit (conn);

終わりを。

関連する問題