shawl.qiu c# .net 发邮件用户控件 v1.0
说明:
写这个只是时间问题,没什么难度, 就不说明什么了。。。
shawl.qiu
2007-04-24
http://blog.csdn.net/btbtd
下载:
http://files.myopera.com/btbtd/csharp/uc/csharp_dotNet_uc_Mails_v_1.0_by_shawl.qiu.7z
相关文章:
ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu
http://blog.csdn.net/btbtd/archive/2006/09/12/1214643.aspx
内容:
1. Mails.aspx
2. Mails.ascx
说明:
写这个只是时间问题,没什么难度, 就不说明什么了。。。
shawl.qiu
2007-04-24
http://blog.csdn.net/btbtd
下载:
http://files.myopera.com/btbtd/csharp/uc/csharp_dotNet_uc_Mails_v_1.0_by_shawl.qiu.7z
相关文章:
ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu
http://blog.csdn.net/btbtd/archive/2006/09/12/1214643.aspx
内容:
1. Mails.aspx
- <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" ValidateRequest="false" %>
- <%@ Reference Control="Mails.ascx" %>
- <script runat="server">
- void Page_Load(Object s, EventArgs e)
- {
- Mails mails = (Mails)LoadControl("Mails.ascx");
- MailPh.Controls.Add(mails);
- mails = null;
- } // end Page_Load
- </script>
- <!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>Untitled Document</title>
- </head>
- <body>
- <form runat="server">
- <asp:Label ID="InfoLabel" runat="server" />
- <asp:PlaceHolder ID="MailPh" runat="server" />
- </form>
- </body>
- </html>
- <%@ Control Language="C#" AutoEventWireup="True" className="Mails" %>
- <%@ import Namespace="System.Text" %>
- <%@ import Namespace="System.Web.Mail" %>
- <script runat="server">
- public const String auSubject = "shawl.qiu c# .net 发邮件用户控件";
- public const String auVersion = "v1.0";
- public const String au = "shawl.qiu";
- public const String auEmail = "shawl.qiu@gmail.com";
- public const String auBlog = "http://blog.csdn.net/btbtd";
- public const String auCreateDate = "2007-4-24";
- public bool Debug = false;
- public string sFrom = "alyy@21cn.com";
- public string sTo = "shawl.qiu@gmail.com";
- public string sCc = "";
- public string sBcc = "";
- public string sSubject = "shawl.qiu c# .net 发邮件测试 "+DateTime.Now;
- public string sFormatDefaultSelect = "0";
- public string sEncoding = "UTF-8";
- public string sText ="Just a test, <b>这是一个测试</b>";
- public string sSmtp = "smtp.21cn.com";
- public string sPort = "25";
- public string sTimeout = "60";
- public string sSsl = "false";
- public string sAuthDefaultSelect = "1";
- public string sUsingDefaultSelect = "2";
- public string sUsername = "alyy";
- public string sPassword = "alyysq";
- void Page_Load(Object s, EventArgs e)
- {
- DspSbjLbl.Text = auSubject+" "+auVersion;
- InfoLabel.Text = "";
- DebugLabel.Text = "";
- if(!IsPostBack)
- {
- FromTbx.Text = sFrom;
- ToTbx.Text = sTo;
- CcTbx.Text = sCc;
- BccTbx.Text = sBcc;
- SubjectTbx.Text = sSubject;
- FormatCbl.SelectedValue = sFormatDefaultSelect+"";
- //EncodingTbx.Text = sEncoding;
- TextTbx.Text = sText;
- SmtpTbx.Text = "smtp.21cn.com";
- PortTbx.Text = sPort+"";
- TimeoutTbx.Text = sTimeout+"";
- SslCbx.Checked = Boolean.Parse(sSsl);
- AuthDdl.SelectedValue = sAuthDefaultSelect+"";
- UsingDdl.SelectedValue = sUsingDefaultSelect+"";
- UsernameTbx.Text = sUsername;
- PasswordTbx.Text = sPassword;
- if(Debug)
- {
- Response.Write("<li/>PasswordTbx.Text: "+PasswordTbx.Text);
- }
- } // end if
- } // end Page_Load
- void SendMailFunc(Object s, EventArgs e)
- {
- SendMail sendMail = new SendMail();
- sendMail.Debug = true;
- sendMail.DebugLabel = DebugLabel;
- sendMail.InfoLabel = InfoLabel;
- sendMail.From = FromTbx.Text;
- sendMail.To = ToTbx.Text;
- sendMail.Cc = CcTbx.Text;
- sendMail.Bcc = BccTbx.Text;
- sendMail.Subject = SubjectTbx.Text;
- sendMail.Format = FormatCbl.SelectedValue;
- sendMail.Text = TextTbx.Text;
- sendMail.Smtp = SmtpTbx.Text;
- sendMail.Port = PortTbx.Text;
- sendMail.Timeout = TimeoutTbx.Text;
- sendMail.Ssl = SslCbx.Checked+"";
- sendMail.Auth = AuthDdl.SelectedValue;
- sendMail.Using = UsingDdl.SelectedValue;
- sendMail.Username = UsernameTbx.Text;
- sendMail.Password = PasswordTbx.Text;
- sendMail.Go();
- sendMail = null;
- }
- /*-----------------------------------------------------------------------------------*/
- * shawl.qiu class SendMail v1.0
- /*-----------------------------------------------------------------------------------*/
- //---------------------------------------------------------------------begin class SendMail
- public class SendMail
- {
- //-----------------------------------begin event
- public SendMail()
- {
- }
- ~SendMail()
- {
- }
- //-----------------------------------end event
- //-----------------------------------begin public constant
- //-----------------------begin about
- public const String auSubject = "shawl.qiu class SendMail v1.0";
- public const String auVersion = "v1.0";
- public const String au = "shawl.qiu";
- public const String auEmail = "shawl.qiu@gmail.com";
- public const String auBlog = "http://blog.csdn.net/btbtd";
- public const String auCreateDate = "2007-4-24";
- //-----------------------end about
- //-----------------------------------end public constant
- //-----------------------------------begin private constant
- //-----------------------------------end private constant
- //-----------------------------------begin public static method
- public static void Message(Label InfoLabel, string msg)
- {
- InfoLabel.Text +="<div style=/"display:table;width:100%;background-color:yellow!important;";
- InfoLabel.Text += "color:black!important;text-align:center!important;/">";
- InfoLabel.Text += msg+"</div>";
- }
- public static void Message(string msg, Label InfoLabel)
- {
- Message(InfoLabel, msg);
- }
- public static void Message(Label InfoLabel, string msg, string charSet)
- {
- InfoLabel.Text+="<meta http-equiv=/"Content-Type/" content=/"text/html; charset="+
- charSet+"/" />";
- Message(InfoLabel, msg);
- }
- //-----------------------------------end public static method
- //-----------------------------------begin private static method
- //-----------------------------------end private static method
- //-----------------------------------begin public variable
- public bool Debug = false;
- public string From = "";
- public string To = "";
- public string Cc = "";
- public string Bcc = "";
- public string Subject = "";
- public string Format = "1";
- public string Encoding = "UTF-8";
- public string Text = "";
- public string Smtp = "";
- public string Port = "25";
- public string Timeout = "60";
- public string Ssl = "false";
- public string Auth = "1";
- public string Using = "2";
- public string Username = "";
- public string Password = "";
- public Label InfoLabel;
- public Label DebugLabel;
- //-----------------------------------end public variable
- //-----------------------------------begin private variable
- //-----------------------------------end private variable
- //-----------------------------------begin public method
- public void Go()
- {
- if(Debug)
- {
- System.Web.HttpContext.Current.Response.Write("<li/>public void Go(): Ok");
- }
- if(From=="")
- {
- if(InfoLabel!=null)
- {
- Message("From 不能为空!", InfoLabel);
- }
- return;
- }
- if(To=="")
- {
- if(InfoLabel!=null)
- {
- Message("To 不能为空!", InfoLabel);
- }
- return;
- }
- if(Subject=="")
- {
- if(InfoLabel!=null)
- {
- Message("Subject 不能为空!", InfoLabel);
- }
- return;
- }
- if(Text=="")
- {
- if(InfoLabel!=null)
- {
- Message("Text 不能为空!", InfoLabel);
- }
- return;
- }
- if(Smtp=="")
- {
- if(InfoLabel!=null)
- {
- Message("Smtp 不能为空!", InfoLabel);
- }
- return;
- }
- if(Username=="")
- {
- if(InfoLabel!=null)
- {
- Message("Username 不能为空!", InfoLabel);
- }
- return;
- }
- if(Password=="")
- {
- if(InfoLabel!=null)
- {
- Message("Password 不能为空!", InfoLabel);
- }
- return;
- }
- if(Encoding=="")
- {
- Encoding = "UTF-8";
- }
- if(Debug)
- {
- System.Web.HttpContext.Current.Response.Write("<li/>From: "+From);
- System.Web.HttpContext.Current.Response.Write("<li/>To: "+To);
- System.Web.HttpContext.Current.Response.Write("<li/>Cc: "+Cc);
- System.Web.HttpContext.Current.Response.Write("<li/>Bcc: "+Bcc);
- System.Web.HttpContext.Current.Response.Write("<li/>Subject: "+Subject);
- System.Web.HttpContext.Current.Response.Write("<li/>Format: "+Format);
- System.Web.HttpContext.Current.Response.Write("<li/>Text: "+Text);
- System.Web.HttpContext.Current.Response.Write("<li/>Smtp: "+Smtp);
- System.Web.HttpContext.Current.Response.Write("<li/>Port: "+Port);
- System.Web.HttpContext.Current.Response.Write("<li/>Timeout: "+Timeout);
- System.Web.HttpContext.Current.Response.Write("<li/>Ssl: "+Ssl);
- System.Web.HttpContext.Current.Response.Write("<li/>Auth: "+Auth);
- System.Web.HttpContext.Current.Response.Write("<li/>Using: "+Using);
- System.Web.HttpContext.Current.Response.Write("<li/>Username: "+Username);
- System.Web.HttpContext.Current.Response.Write("<li/>Password: "+Password);
- } // end if
- MailMessage mm = new MailMessage();
- mm.From = From;
- mm.To = To;
- if(Cc!="") mm.Cc = Cc;
- if(Bcc!="") mm.Bcc = Bcc;
- mm.Subject = Subject;
- switch(Format)
- {
- case "0":
- mm.BodyFormat = MailFormat.Text;
- break;
- case "1":
- mm.BodyFormat = MailFormat.Html;
- break;
- default:
- break;
- }
- mm.Body = Text;
- mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", Using.Trim());
- //mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", Smtp);
- mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", Auth.Trim());
- mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", Port.Trim());
- mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Username.Trim());
- mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password.Trim());
- mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", Timeout.Trim());
- mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", Boolean.Parse(Ssl));
- SmtpMail.SmtpServer = Smtp.Trim();
- SmtpMail.Send(mm);
- mm = null;
- } // end public void Go
- //-----------------------------------end public method
- //-----------------------------------begin private method
- //-----------------------------------end private method
- //-----------------------------------begin public property
- //-----------------------------------end public property
- //-----------------------------------begin private property
- //-----------------------------------end private property
- }
- //---------------------------------------------------------------------end class SendMail
- </script>
- <style type="text/css">
- /* <![CDATA[ */
- .MailsTbl
- {
- margin: 5px 0px;
- }
- .MailsTbl tr td
- {
- padding: 2px;
- }
- .CssMainWidth
- {
- width:60%;
- }
- /* ]]> */
- </style>
- <asp:Label ID="InfoLabel" runat="server" />
- <asp:Label ID="DebugLabel" runat="server" />
- <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="MailsTbl">
- <tr align="center">
- <td colspan="2">
- <strong><asp:Label ID="DspSbjLbl" runat="server" /></strong>
- </td>
- </tr>
- <tr>
- <td width="120" align="right" valign="top">From:</td>
- <td>
- <asp:TextBox ID="FromTbx" runat="server"
- CssClass="CssMainWidth"
- />
- </td>
- </tr>
- <tr>
- <td width="120" align="right" valign="top">To:</td>
- <td>
- <asp:TextBox ID="ToTbx" runat="server"
- CssClass="CssMainWidth"
- Rows=3
- TextMode="MultiLine"
- />
- </td>
- </tr>
- <tr>
- <td width="120" align="right" valign="top">CC:</td>
- <td>
- <asp:TextBox ID="CcTbx" runat="server"
- CssClass="CssMainWidth"
- />
- </td>
- </tr>
- <tr>
- <td width="120" align="right" valign="top">BCC:</td>
- <td>
- <asp:TextBox ID="BccTbx" runat="server"
- CssClass="CssMainWidth"
- />
- </td>
- </tr>
- <tr>
- <td width="120" align="right" valign="top">Subject:</td>
- <td>
- <asp:TextBox ID="SubjectTbx" runat="server"
- CssClass="CssMainWidth"
- />
- </td>
- </tr>
- <tr>
- <td width="120" align="right" valign="top">Text Format:</td>
- <td>
- <asp:RadioButtonList ID="FormatCbl" runat="server"
- RepeatDirection="Horizontal"
- RepeatLayout="Flow"
- >
- <asp:ListItem Value="0">Text</asp:ListItem>
- <asp:ListItem Value="1">HTML</asp:ListItem>
- </asp:RadioButtonList>
- </td>
- </tr>
- <tr>
- <td align="right" valign="top">Text Encoding: </td>
- <td>
- <%-- <asp:TextBox ID="EncodingTbx" runat="server" /> --%>
- </td>
- </tr>
- <tr>
- <td width="120" align="right" valign="top">Text:</td>
- <td>
- <asp:TextBox ID="TextTbx" runat="server"
- CssClass="CssMainWidth"
- Rows=10
- TextMode="MultiLine"
- />
- </td>
- </tr>
- <tr>
- <td width="120" align="right" valign="top">Remote SMTP: </td>
- <td>
- <asp:TextBox ID="SmtpTbx" runat="server"
- />
- </td>
- </tr>
- <tr>
- <td width="120" align="right" valign="top">Port:</td>
- <td>
- <asp:TextBox ID="PortTbx" runat="server"
- Size=5
- />
- </td>
- </tr>
- <tr>
- <td width="120" align="right" valign="top">Timeout:</td>
- <td>
- <asp:TextBox ID="TimeoutTbx" runat="server"
- Size=5
- />
- (Unit: Second) </td>
- </tr>
- <tr>
- <td width="120" align="right" valign="top">SSL:</td>
- <td>
- <asp:CheckBox ID="SslCbx" runat="server"
- />
- </td>
- </tr>
- <tr>
- <td align="right" valign="top">SMTP验证选项: </td>
- <td>
- <asp:DropDownList ID="AuthDdl" runat="server"
- RepeatDirection="Horizontal"
- RepeatLayout="Flow"
- >
- <asp:ListItem Value="0">匿名验证</asp:ListItem>
- <asp:ListItem Value="1">普通验证</asp:ListItem>
- <asp:ListItem Value="2">NTLM 验证</asp:ListItem>
- </asp:DropDownList>
- </td>
- </tr>
- <tr>
- <td align="right" valign="top">邮件发送选项:</td>
- <td>
- <asp:DropDownList ID="UsingDdl" runat="server"
- RepeatDirection="Horizontal"
- RepeatLayout="Flow"
- >
- <asp:ListItem Value="1">Send Using Pickup</asp:ListItem>
- <asp:ListItem Value="2">Send Using Port</asp:ListItem>
- </asp:DropDownList>
- </td>
- </tr>
- <tr>
- <td align="right" valign="top">Username:</td>
- <td>
- <asp:TextBox ID="UsernameTbx" runat="server"
- />
- </td>
- </tr>
- <tr>
- <td align="right" valign="top">Password:</td>
- <td>
- <asp:TextBox ID="PasswordTbx" runat="server"
- />
- </td>
- </tr>
- <tr>
- <td align="right" valign="top"> </td>
- <td>
- <input type="submit" value="Submit" runat="server"
- onclick="return confirm('现在发送邮件吗?')"
- OnServerClick=SendMailFunc
- />
- <input type="reset" name="Reset" value="Reset"
- onclick="return confirm('现在重置吗?')"
- />
- </td>
- </tr>
- </table>