-
Notifications
You must be signed in to change notification settings - Fork 17
/
body.plsql
86 lines (60 loc) · 2.95 KB
/
body.plsql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
create or replace package body mailer as
c_seperator constant varchar2(19) := 'tq84$tq84$tq84$tq84';
procedure auth_login( -- {
smtp in out utl_smtp.connection,
username in varchar2,
password in varchar2) is
begin
utl_smtp.command(smtp, 'AUTH LOGIN');
utl_smtp.command(smtp, utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(username))));
utl_smtp.command(smtp, utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(password))));
end auth_login; -- }
procedure header ( -- {
smtp in out utl_smtp.connection,
mail_addr_from in varchar2,
mail_addr_to in varchar2,
subject in varchar2)
is
begin
utl_smtp.write_data(smtp, 'Date: ' || to_char(sysdate, 'dd-mon-yyyy hh24:mi:ss') || utl_tcp.crlf);
utl_smtp.write_data(smtp, 'To: ' || mail_addr_to || utl_tcp.crlf);
utl_smtp.write_data(smtp, 'From: ' || mail_addr_from || utl_tcp.crlf);
utl_smtp.write_data(smtp, 'Subject: ' || subject || utl_tcp.crlf);
utl_smtp.write_data(smtp, 'reply-to: ' || mail_addr_from || UTL_TCP.crlf);
utl_smtp.write_data(smtp, 'MIME-Version: 1.0' || utl_tcp.crlf);
utl_smtp.write_data(smtp, 'Content-Type: multipart/mixed; boundary="' || c_seperator || '"' || utl_tcp.crlf || utl_tcp.crlf);
end header; -- }
procedure html(smtp in out utl_smtp.connection, -- {
html in varchar2) is
begin
utl_smtp.write_data(smtp, '--' || c_seperator || utl_tcp.crlf);
utl_smtp.write_data(smtp, 'Content-Type: text/html' || utl_tcp.crlf || utl_tcp.crlf);
utl_smtp.write_data(smtp, html);
utl_smtp.write_data(smtp, utl_tcp.crlf || utl_tcp.crlf);
return;
end html; -- }
procedure attachment( -- {
smtp in out utl_smtp.connection,
filename in varchar2,
content in blob) is
c_step constant pls_integer := 12000; -- Multiple of 3, not higher than 24573
begin
utl_smtp.write_data(smtp, '--' || c_seperator || utl_tcp.crlf);
utl_smtp.write_data(smtp, 'Content-Type: application/octet-stream; name="' || filename || '"' || utl_tcp.crlf);
utl_smtp.write_data(smtp, 'Content-Transfer-Encoding: base64' || UTL_TCP.crlf);
utl_smtp.write_data(smtp, 'Content-Disposition: attachment; filename="' || filename || '"' || utl_tcp.crlf || utl_tcp.crlf);
for i in 0 .. trunc((dbms_lob.getlength(content) - 1 )/c_step) loop
utl_smtp.write_data(smtp, utl_raw.cast_to_varchar2(utl_encode.base64_encode(DBMS_LOB.substr(content, c_step, i * c_step + 1))));
end loop;
utl_smtp.write_data(smtp, utl_tcp.crlf || utl_tcp.crlf);
end attachment; -- }
procedure end_mail( -- {
smtp in out utl_smtp.connection
) is
begin
utl_smtp.write_data(smtp, '--' || c_seperator || '--' || utl_tcp.crlf);
utl_smtp.close_data(smtp);
utl_smtp.quit(smtp);
end end_mail; -- }
end mailer;
/