The utl_mime package requires the EXECUTE privilege on the following packages:
Here a quick example using Google Mail:
declare
l_connection utl_smtp.connection;
l_mail utl_mime.mail_r;
l_blob blob;
l_clob clob;
begin
/* Establish the SMTP connection */
l_connection :=
utl_smtp.open_connection(
host => 'smtp.gmail.com',
port => 587,
wallet_path => 'file:C:/Oracle/Ora11204/BIN/owm/wallets/Administrator',
wallet_password => 'my_secret',
secure_connection_before_smtp => false);
/* Authentication */
utl_smtp.ehlo(l_connection, 'smtp.gmail.com');
utl_smtp.starttls(l_connection);
utl_smtp.ehlo(l_connection, 'smtp.gmail.com');
utl_smtp.auth(l_connection, 'john.doe', 'john_secret', utl_smtp.all_schemes);
/* Select the sending mailbox */
utl_smtp.mail(l_connection, 'john.doe');
/* Send all the recipient mailboxes */
utl_smtp.rcpt(l_connection, 'sue.doe@yahoo.com');
utl_smtp.rcpt(l_connection, 'tom.doe@web.de');
utl_smtp.rcpt(l_connection, 'father.doe@gmail.com');
/* Build the MIME body */
/* Set the authors (aka "From:") */
l_mail.author :=
utl_mime.address_va(utl_mime.address('john.doe@gmail.com', 'Johnny Doe'));
/* Set the recipients (aka "To:") */
l_mail.recipients :=
utl_mime.address_va(
utl_mime.address('sue.doe@yahoo.com', 'Sue Doe'),
utl_mime.address('tom.doe@web.de', 'Tom Doe')
);
/* Set the additional recipients (aka "CC:") */
l_mail.cc := utl_mime.address_va(utl_mime.address('father.doe@gmail.com', 'The Father'));
/* Set the subject of the message */
l_mail.subject := 'Family Party';
/* Set the plain text variant of the message */
l_mail.text := 'Come to our party!';
/* Set the rich-text HTML variant of the message. Note the "src" attribute of the "img" tag */
l_mail.html.text := '<html><body><p>Come to our <em>party</em>!</p>' ||
'<hr><img src="cid:#myname#"></body></html>';
/* Get a BLOB containing a PNG image */
select image into l_blob from images;
/* Set the attachments references by the HTML, i.e. the image */
l_mail.html.attachments :=
utl_mime.attachment_va(
utl_mime.attachment(l_blob, 'image/png', 'myname', 'myfilename.png')
);
/* Set the general attachments (not referenced in the HTML) */
l_mail.attachments :=
utl_mime.attachment_va(
utl_mime.attachment(l_blob, 'image/png', 'ÄÖÜeß߀€§§YZ', 'Amyf€€il§§ÖÖ€meXYZ.png'),
utl_mime.attachment(l_blob, 'image/png', 'myname2', 'myßßßseäöüißßßßlename.png')
);
/* Set the importance of the message */
l_mail.importance := utl_mime.high;
/* Get the MIME body as a CLOB */
l_clob := utl_mime.build(l_mail);
/* Stream the CLOB over the SMTP connection */
utl_mime.write(l_connection, l_clob);
/* Done */
utl_smtp.quit(l_connection);
end;
/