导航:首页 > 源码编译 > 配源码封装邮件

配源码封装邮件

发布时间:2023-03-10 01:09:35

㈠ 求网页邮件类的源码

php
<?

$smtpserver = "smtp.163.com";//SMTP服务器
$smtpserverport =25;//SMTP服务器端口
$smtpusermail = "[email protected]";//SMTP服务器的用户邮箱
$smtpemailto = "[email protected]";//发送给谁
$smtpuser = "[email protected]";//SMTP服务器的用户帐号
$smtppass = "sdffds";//SMTP服务器的用户密码
$mailsubject = $_POST["form_name"];//邮件主题
$mailbody = "内容";//邮件内容
$mailtype = "TXT";//邮件格式(HTML/TXT),TXT为文本邮件

$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
$smtp->debug = FALSE;//是否显示发送的调试信息
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
class smtp
{
/* Public Variables */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;

/* Private Variables */
var $sock;

/* Constractor */
function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()
#
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
#
$this->host_name = "localhost"; //is used in HELO command
$this->log_file ="";

$this->sock = FALSE;
}

/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\\.)", "\\1.\\3", $body);
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));

if ($cc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}

if ($bcc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}

$sent = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
} else {
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote host\n");
}
echo "<br>";
echo $header;
return $sent;
}

/* Private Functions */

function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo)) {
return $this->smtp_error("sending HELO command");
}
#auth
if($this->auth){
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {
return $this->smtp_error("sending HELO command");
}

if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
return $this->smtp_error("sending HELO command");
}
}
#
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {
return $this->smtp_error("sending MAIL FROM command");
}

if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {
return $this->smtp_error("sending RCPT TO command");
}

if (!$this->smtp_putcmd("DATA")) {
return $this->smtp_error("sending DATA command");
}

if (!$this->smtp_message($header, $body)) {
return $this->smtp_error("sending message");
}

if (!$this->smtp_eom()) {
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}

if (!$this->smtp_putcmd("QUIT")) {
return $this->smtp_error("sending QUIT command");
}

return TRUE;
}

function smtp_sockopen($address)
{
if ($this->relay_host == "") {
return $this->smtp_sockopen_mx($address);
} else {
return $this->smtp_sockopen_relay();
}
}

function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;;
}

function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\\1", $address);
if (!@getmxrr($domain, $MXHOSTS)) {
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host) {
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}

function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));

return TRUE;
}

function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");

return $this->smtp_ok();
}

function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");

if (!ereg("^[23]", $response)) {
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}

function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
if($cmd=="") $cmd = $arg;
else $cmd = $cmd." ".$arg;
}

fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");

return $this->smtp_ok();
}

function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}

function log_write($message)
{
$this->smtp_debug($message);

if ($this->log_file == "") {
return TRUE;
}

$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);

return TRUE;
}

function strip_comment($address)
{
$comment = "\\([^()]*\\)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}

return $address;
}

function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\\1", $address);

return $address;
}

function smtp_debug($message)
{
if ($this->debug) {
echo $message."<br>";
}
}

function get_attach_type($image_tag) { //

$filedata = array();

$img_file_con=fopen($image_tag,"r");
unset($image_data);
while ($tem_buffer=AddSlashes(fread($img_file_con,filesize($image_tag))))
$image_data.=$tem_buffer;
fclose($img_file_con);

$filedata['context'] = $image_data;
$filedata['filename']= basename($image_tag);
$extension=substr($image_tag,strrpos($image_tag,"."),strlen($image_tag)-strrpos($image_tag,"."));
switch($extension){
case ".gif":
$filedata['type'] = "image/gif";
break;
case ".gz":
$filedata['type'] = "application/x-gzip";
break;
case ".htm":
$filedata['type'] = "text/html";
break;
case ".html":
$filedata['type'] = "text/html";
break;
case ".jpg":
$filedata['type'] = "image/jpeg";
break;
case ".tar":
$filedata['type'] = "application/x-tar";
break;
case ".txt":
$filedata['type'] = "text/plain";
break;
case ".zip":
$filedata['type'] = "application/zip";
break;
default:
$filedata['type'] = "application/octet-stream";
break;
}
return $filedata;
}

}
?>

㈡ 导出邮件源码后如何将源码制成另一封邮件

你说的源码是什么样式的?类似下面这样的吗?

Return-Path: [email protected]
Received: from mail.163.com (LHLO smtp.163.com) (210.36.16.60) by
gxumail09.163.com with LMTP; Tue, 8 Jun 2010 10:07:43 +0800 (CST)
Received: from localhost (localhost.localdomain [127.0.0.1])
by smtp.163.com (tmailer) with ESMTP id C148EBFF1F
for <[email protected]>; Tue, 8 Jun 2010 10:07:43 +0800 (CST)
Received: from smtp.163.com ([127.0.0.1])
by localhost (gxumail09.163.com [127.0.0.1]) (theinterface-new, port 10024)
with ESMTP id WafFSKLzv3Rg for <[email protected]>;
Tue, 8 Jun 2010 10:07:30 +0800 (CST)
Received: from gxukjy-fd10bb9d (unknown [172.18.254.20])
by smtp.163.com (tmailer) with ESMTPA id 01D19BFF99
for <[email protected]>; Tue, 8 Jun 2010 10:07:28 +0800 (CST)
Date: Tue, 8 Jun 2010 10:03:02 +0800
From: "ln6047" <[email protected]>
To: "zdxm" <[email protected]>
Subject: =?gb2312?B?uePO97Tz0ae/xry81LCy+tGn0dDGvcyovajJ6M/uxL+=?=
Message-ID: <[email protected]>
X-mailer: Foxmail 6, 15, 201, 20 [cn]
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="=====001_Dragon804820203587_====="

好像不管用什么办法,Received头一定会有变化喔。目前只能保证收件人收到邮件后看到的发件人、收件人以及邮件内容没有变化。

㈢ 求java实现邮件发送的源代码

import java.util.*;
import javax.mail.*;import javax.mail.internet.*;
public class JMail {
public void SendMail(String Topic,String Content){ Properties props=new Properties(); props.put("mail.smtp.host","smtp.163.com"); props.put("mail.smtp.auth","true"); Session s=Session.getInstance(props); s.setDebug(false); MimeMessage message=new MimeMessage(s); MimeMultipart mp=new MimeMultipart(); BodyPart body = new MimeBodyPart(); InternetAddress from; InternetAddress to; try{ from=new InternetAddress("发件人邮箱"); message.setFrom(from); to = new InternetAddress("收件人邮箱"); message.setRecipient(Message.RecipientType.TO,to); message.setSubject(Topic,"utf-8"); body.setContent(Content, "text/html;charset=utf-8"); mp.addBodyPart(body); message.setContent(mp); message.setSentDate(new Date()); message.saveChanges(); Transport transport=s.getTransport("smtp"); transport.connect("smtp.163.com(邮件服务商,这是163的)","发件邮箱","发件邮箱密码"); transport.sendMessage(message,message.getAllRecipients()); transport.close(); } catch(AddressException e){ e.printStackTrace(); } catch(MessagingException e){ e.printStackTrace(); } }}

㈣ 其他部门借开发源码怎么发邮件

在 .net1.1 ,用System.Web.Mail发送邮件。在.net2.0及之后版本,用System.Net.Mail发送邮件。主要用到了在.net2.0中新增的两个类,分别是System.Net.Mail.MailMessage和System.Net.Mail.SmtpClient两个类,在SMTP身份验证方面用到了System.Net.NetworkCredential类。

㈤ 谁可以给我个好用点的邮件发送功能的源码

先下载个jmail安装(如果是虚拟主机一般都已经安装支持)
在项目中添加引用,选择jmail安装目录中的jmail.dll

代码:

myJmail.Message jmail=new myJmail.Message();
DateTime t=DateTime.Now;
string subject= tbTitle.Text;
string body= tbContent.Text.Replace("\n","<br>");
string fromemail="[email protected]";
string toEmail= tbUserMail.Text;
//silent属性:如果设置为true,jmail不会抛出例外错误. jmail. send( () 会根据操作结果返回true或false
jmail.Silent = true;
//jmail创建的日志,前提loging属性设置为true
jmail.Logging=true;
//字符集,缺省为"us-ascii"
jmail.Charset="gb2312";
//信件的contentype. 缺省是"text/plain") : 字符串如果你以html格式发送邮件, 改为"text/html"即可。
jmail.ContentType="text/html";
//添加收件人
jmail.AddRecipient(toEmail,"","");
jmail.From=fromemail;
//发件人邮件用户名
jmail.MailServerUserName="XXXXXX" ;
//发件人邮件密码
jmail.MailServerPassWord="********" ;
//设置邮件标题
jmail.Subject=subject;
//邮件添加附件,(多附件的话,可以再加一条jmail.addattachment( "c:\\test.jpg",true,null);)就可以搞定了。〔注〕:加了附件,讲把上面的jmail.contenttype="text/html";删掉。否则会在邮件里出现乱码。
//jmail.addattachment( "c:\\test.jpg",true,null);
//邮件内容
jmail.Body=body;
//jmail发送的方法

if(jmail.Send("smtp.163.com",false))
UserChecker.classes.Common.ShowMessage("已成功发送邮件。");
else
UserChecker.classes.Common.ShowMessage("发送邮件失败!!!");
jmail.Close() ;

这些代码已经测试通过.有一点:jmail.From中出现的用户名必须与jmail.MailServerUserName相关.比如说上面用于发送邮件的帐号是[email protected],那么jmail.From必须是XXXXXX,否则会发送失败!!!!

㈥ 我有一个PHP发邮件的源码,但是发邮件时候不填标题跟内容也可以发送成功,我想在源码里添加一个判断提示

if($mailtitle==""){
echo '<script language="JavaScript">;alert("发送失败!请填写完整信息。");location.href="index.html";</script>;';
echo "<a href='index.html'>点此返回</a>";
exit();
}
这可以判断你邮箱有没有填写

阅读全文

与配源码封装邮件相关的资料

热点内容
基本初等函数的导数公式及导数的运算法则 浏览:915
为什么小米app启动广告关不了 浏览:877
空调压缩机一直不停 浏览:511
养殖系统开发源码 浏览:82
pdf的目录 浏览:406
光遇安卓如何一个人拍视频 浏览:277
怨女pdf 浏览:708
扭曲服务器什么时候开 浏览:23
加密货币换平台 浏览:609
手机内存压缩软件 浏览:33
生成树是否与遍历算法有关 浏览:728
python强化学习迷宫 浏览:450
老包子解压视频 浏览:885
服务器注册是什么意思 浏览:418
程序员群体焦虑如何破局 浏览:585
程序员在广州上班 浏览:803
androidlinuxadt 浏览:512
广联达软件加密锁原装芯片 浏览:338
如何打开数据库服务器 浏览:310
kppm是什么app 浏览:538