|
如何利用ASP程序來使用JMail發郵件的例子
|
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
if Request("MailtoAddress") <> "" then
msg = SendMail
(Request("SMTPServer"),Request("SMTPServerUserName"),Request("SMTPServerPassword"),
Request("MailDomain"),Request("MailtoAddress"),Request("MailtoName"),Request("Subject"),
Request("MailBody"),Request("FromName"),Request("MailFrom"),Request("Priority"))
if msg then Response.Write("發送成功") else Response.Write("發送不成功")
Response.End()
end if
function
SendMail(SMTPServer,SMTPServerUserName,SMTPServerPassword,MailDomain,MailtoAddress,MailtoName,
Subject,MailBody,FromName,MailFrom,Priority)
dim JMail, msg
set JMail=Server.CreateObject("JMail.Message")
JMail.Charset="gb2312" '編碼
JMail.silent=true '設置為true,JMail不會拋出例外錯誤.
JMail.ContentType = "text/plain" '郵件正文格式
'JMail.ServerAddress = SMTPServer '用來發送郵件的SMTP服務器(無效)
'指定郵件服務器的地址。可以指定多個服務器,用分號點開。可以指定端口號。
'如果serverAddress保持空白,JMail會嘗試解決遠程郵件服務器,然後直接發送到服務器上去。???
'如:JMail.ServerAddress = &tquo;mail.mydom.net; mail2.mydom.net:2500"
JMail.MailServerUserName = SMTPServerUserName '登錄用戶名
JMail.MailServerPassWord = SMTPServerPassword '登錄密碼
JMail.MailDomain = MailDomain '域名(如果用“name@domain.com”這樣的用戶名登錄時,請指明domain.com
JMail.AddRecipient MailtoAddress,MailtoName '收信人
JMail.Subject = Subject '主題
JMail.Body = MailBody '郵件正文(純文本格式)
JMail.FromName = FromName '發信人姓名
JMail.From = MailFrom '發信人Email
JMail.Priority = Priority '郵件等級12345
msg = JMail.Send(SMTPServer)
JMail.Close
set JMail = nothing
SendMail = msg
end function
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JMail test</title>
</head>
<body>
<form name="form1" method="post" action="">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#333333">
<tr bgcolor="#FFFFFF">
<!--
<td width="14%"> SMTP服務器地址: </td>
<td width="86%"><input name="SMTPServer" type="text" id="SMTPServer" value="smtp.126.com"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="14" colspan="2">如果該SMTP需要身份驗證,還需要填以下信息:</td>
</tr>
<tr bgcolor="#FFFFFF">
<td> SMTP登錄用戶名: </td>
<td><input name="SMTPServerUserName" type="text" id="SMTPServerUserName" value=""></td>
</tr>
<tr bgcolor="#FFFFFF">
<td> SMTP登錄密碼: </td>
<td><input name="SMTPServerPassword" type="password" id="SMTPServerPassword" value=""></td>
</tr>
<tr bgcolor="#FFFFFF">
<td> SMTP域名 : </td>
<td><input name="MailDomain" type="text" id="MailDomain" value=""></td>
</tr>
<tr bgcolor="#FFFFFF">
<td> </td>
<td> </td>
</tr>
-->
<tr bgcolor="#FFFFFF">
<td>收件人郵箱:</td>
<td><input name="MailtoAddress" type="text" id="MailtoAddress"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>收件人:</td>
<td><input name="MailtoName" type="text" id="MailtoName"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>主題:</td>
<td><input name="Subject" type="text" id="Subject"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>內容:</td>
<td><textarea name="MailBody" id="MailBody"></textarea></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>發件人郵箱:</td>
<td><input name="MailFrom" type="text" id="MailFrom"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>發件人:</td>
<td><input name="FromName" type="text" id="FromName"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td> </td>
<td> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td>等級:</td>
<td><select name="Priority" id="Priority">
<option value="5">5</option>
<option value="4">4</option>
<option value="3" selected>3</option>
<option value="2">2</option>
<option value="1">1</option>
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2"><input type="submit" name="Submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html> |
返 回 |
|