求C#发送和收取的源代码
求C#发送和收取的源代码
------解决方案--------------------MailPriority enum 设置邮件优先权。价值: 高, 低, 正常
<% @Import Namespace = "System.Web.Util " %>
OK第一部已经完成了
步骤2: MailMessage 对象示例
声明MailMessage对象。
Dim mailObj AS new MailMessage
MailMessage 对象属性:
属性 描述
From 发信人的地址
To 收信人的地址
Subject 邮件主题
Body 邮件正文
cc 邮件副本接受人地址
bcc 邮件副本接受人地址比显示在邮件中(密件)
Priority 邮件的优先权
BodyEncoding 邮件内码
BodyFormat 邮件格式,html或文本
Attachments 邮件附件
以下的代码片断将展示MailMessage 对象。
mailObj.From = "abc@mydomain.com "
mailObj.To = Request.Form ( "to ")
mailObj.Subject = "subject of the mail "
mailObj.Body = "Message of the mail "
发送邮件使用SmtpMail 对象Send 方法。以下代码片断被使用送邮件
SmtpMail.Send(mailObj)
vb.net完整源代码
<%@page language= "VB " %>
<%@Import Namespace= "System.Web.Util " %>
<HTML>
<head>
<title> 欢迎使用chenyangasp示例程序
</title>
</head>
<BODY>
<SCRIPT LANGUAGE= "VB " RUNAT= "server ">
' 这个方法当提交时访问服务器
Sub SendMail (Obj As Object, E As EventArgs)
Dim mailObj AS new MailMessage
'设置邮件的发送及接收地址
mailObj.From = Request.Form( "From ")
mailObj.To = Request.Form( "To ")
mailObj.Subject = "Subject Of the Mail "
mailObj.Body = "Body of the Mail "
'html格式的邮件
mailObj.BodyFormat = MailFormat.Html
'设置为高级优先权
mailObj.Priority = MailPriority.High
'为邮件添加附件
'注意:这里我们创建了一个mailattachment对象添加一个附件到邮件中
mailObj.Attachments.Add(new MailAttachment( "c:\test.doc "))
'使用SmtpMail对象发送邮件
SmtpMail.Send(mailObj)
End Sub
</SCRIPT>
<asp:label ID= "Headingmsg " Text= "Enter Your Email Address: " RUNAT= "server "/>
<FORM METHOD= "post " RUNAT= "server ">
Email Recipient: <INPUT TYPE= "text " NAME= "to ">
Email Sender: <INPUT TYPE= "text " NAME= "from ">
<INPUT TYPE= "submit " NAME= "Submit " VALUE= "Send Mail " RUNAT= "server " OnServerClick= "SendMail ">
</FORM>
</BODY>
C#完整源代码
<%@page language= "C# " %>
<%@Import Namespace= "System.Web.Util " %>
<HTML>
<head>
<title> 欢迎使用chenyangasp示例程序
</title>
</head>
<BODY>
<SCRIPT LANGUAGE= "C# " RUNAT= "server ">
// 这个方法当提交时访问服务器
public void SendMail (Object Obj, EventArgs E)
{
MailMessage mailObj = new MailMessage();
// 设置邮件的发送及接收地址
mailObj.From = Request.Form( "From ");
mailObj.To = Request.Form( "To ");
mailObj.Subject = "Subject Of the Mail ";
mailObj.Body = "Body of the Mail ";
// html格式的邮件
mailObj.BodyFormat = MailFormat.Html;
// 设置为高级优先权
mailObj.Priority = MailPriority.High;
// 为邮件添加附件
// 注意:这里我们创建了一个mailattachment对象添加一个附件到邮件中
mailObj.Attachments.Add(new MailAttachment( "c:\\test.doc "));
// 使用SmtpMail对象发送邮件
SmtpMail.Send(mailObj);
}
</SCRIPT>
<asp:label ID= "Headingmsg " Text= "Enter Your Email Address: " RUNAT= "server "/>
<FORM METHOD= "post " RUNAT= "server ">