–发送邮件的主过程如下所述:
‘); –设置发件人
— 设置收件人—————-
Psrc := Rtrim(Ltrim(p_To,’;’),’;’) || ‘;’;
Psrc1 := Rtrim(Ltrim(p_Touser,’;’) || ‘;’;
IF Nvl(Instr(Psrc,’;’,j),0)>0 THEN
LOOP
i := Nvl(Instr(Psrc,0);
m := Nvl(Instr(Psrc1,n),0);
If i > 0 THEN
v_To := Trim(Substr(Psrc,j,i – j));
v_Touser := nvl(Trim(Substr(Psrc1,n,m – n)),’1′);
Utl_Smtp.Rcpt(v_Conn,v_To); –设置收件人
IF v_Touser = ‘1’ THEN
v_Touser := trim(SUBSTR(v_To,1,Instr(v_To,’@’)-1));
END IF;
IF j = 1 THEN
v_Touser1 := v_Touser1 || v_Touser || ‘<' || v_To || '>‘;
ELSE
v_Touser1 := v_Touser1 || ‘;’|| v_Touser || ‘<' || v_To || '>‘;
END IF;
j := i + 1;
n := m + 1;
END IF;
Exit When i = 0;
END LOOP;
ELSE
Utl_Smtp.Rcpt(v_Conn,p_To); –设置收件人
v_Touser1 := v_Touser1 || p_Touser || ‘<' || p_To || '>‘;
END IF;
— 设置抄送人—————-
i := 1;
j := 1;
IF nvl(p_Cc,’aa’)<>‘aa’ THEN
Psrc := Rtrim(Ltrim(p_Cc,’;’)|| ‘;’;
IF Nvl(Instr(Psrc,i – j));
j := i + 1;
Utl_Smtp.Rcpt(v_Conn,v_To); –设置抄送人
END IF;
Exit When i = 0;
END LOOP;
ELSE
IF nvl(p_Cc,’1′) <> ‘1’ THEN
Utl_Smtp.Rcpt(v_Conn,p_Cc); –设置抄送人
END IF;
END IF;
END IF;
— 创建要发送的邮件内容注意报头信息和邮件正文之间要空一行
v_Msg := ‘Date: ‘ || To_Char(Sysdate,’dd mon yy hh24:mi:ss’) || Utl_Tcp.Crlf ||
‘From: ‘ || p_Fromuser || ‘<' || p_From || '>‘ || Utl_Tcp.Crlf ||
‘To: ‘ || v_Touser1 || Utl_Tcp.Crlf ||
‘Cc: ‘ || p_Cc || Utl_Tcp.Crlf ||
‘Subject: ‘ || p_Subject || Utl_Tcp.Crlf ||
Utl_Tcp.Crlf — 这前面是报头信息
|| p_Message; — 这个是邮件正文
Utl_Smtp.Open_Data(v_Conn); –打开流
Utl_Smtp.Write_Raw_Data(v_Conn,Utl_Raw.Cast_To_Raw(Convert(‘Content-Type:text/html;charset=utf-8′ ||
v_Msg,’ZHS16GBK’))); –这样写标题和内容都能用中文
Utl_Smtp.Close_Data(v_Conn); –关闭流
Utl_Smtp.Quit(v_Conn); –关闭连接
Exception
When Others THEN
str_error := Dbms_Utility.Format_Error_Stack || Dbms_Utility.Format_Call_Stack;
Dbms_Output.Put_Line(str_error);
END;
以上所述是小编给大家带来的利用Oracle数据库发送邮件的实例代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的,在此也非常感谢大家对脚本之家网站的支持!