導航:首頁 > 源碼編譯 > 配源碼封裝郵件

配源碼封裝郵件

發布時間: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();
}
這可以判斷你郵箱有沒有填寫

閱讀全文

與配源碼封裝郵件相關的資料

熱點內容
加密貨幣換平台 瀏覽:609
手機內存壓縮軟體 瀏覽:33
生成樹是否與遍歷演算法有關 瀏覽:727
python強化學習迷宮 瀏覽:449
老包子解壓視頻 瀏覽:885
伺服器注冊是什麼意思 瀏覽:418
程序員群體焦慮如何破局 瀏覽:584
程序員在廣州上班 瀏覽:802
androidlinuxadt 瀏覽:512
廣聯達軟體加密鎖原裝晶元 瀏覽:338
如何打開資料庫伺服器 瀏覽:310
kppm是什麼app 瀏覽:538
python多個數組命名 瀏覽:192
a演算法csdn 瀏覽:23
r720伺服器什麼年代 瀏覽:975
本地電腦怎麼設置傳奇伺服器 瀏覽:1002
安卓10框架怎麼製作 瀏覽:959
程序員退休工資待遇 瀏覽:609
湛江中文編程數控系統代理 瀏覽:419
openglandroid書 瀏覽:170