defaultcs.aspx.cs
来自「Telerik是很大的第三方软件制造商」· CS 代码 · 共 85 行
CS
85 行
using System;
using System.IO;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using Telerik.WebControls;
using Telerik.WebControls.RadUploadUtils;
namespace Telerik.UploadExamplesCSharp.WebBasedMailClient
{
public class DefaultCS : Telerik.QuickStart.XhtmlPage
{
protected Label lblMailSent;
protected TextBox txtFrom;
protected TextBox txtTo;
protected TextBox txtSubject;
protected TextBox txtCC;
protected TextBox txtBCC;
protected TextBox txtBody;
protected Panel pnlMailForm;
protected RequiredFieldValidator fromRequiredValidator;
protected RegularExpressionValidator fromRegexValidator;
protected Button btnSend;
protected RadUpload upload1;
protected RegularExpressionValidator ccRegexValidator;
protected RegularExpressionValidator bccRegexValidator;
protected RadUploadProgressArea progressArea1;
private void Page_Load(object sender, System.EventArgs e)
{
}
private void btnSend_Click(object sender, System.EventArgs e)
{
SmtpMail.SmtpServer = "localhost";
SendMail();
lblMailSent.Visible = true;
pnlMailForm.Visible = false;
}
private void SendMail()
{
MailMessage theMessage = new MailMessage();
theMessage.From = txtFrom.Text;
theMessage.To = txtTo.Text;
theMessage.Subject = txtSubject.Text;
theMessage.Cc = txtCC.Text;
theMessage.Bcc = txtBCC.Text;
string[] tempFileNames = new string[upload1.UploadedFiles.Count];
for (int i=0; i<upload1.UploadedFiles.Count; i++)
{
UploadedFile currentUploadedFile = upload1.UploadedFiles[i];
tempFileNames[i] = Request.MapPath(string.Format("./{0}", currentUploadedFile.FileName.Substring(currentUploadedFile.FileName.LastIndexOf("\\") + 1)));
currentUploadedFile.SaveAs(tempFileNames[i]);
MailAttachment currentAttachment = new MailAttachment(tempFileNames[i]);
theMessage.Attachments.Add(currentAttachment);
}
theMessage.Body = txtBody.Text;
//SmtpMail.Send(theMessage);
foreach (string tempFileName in tempFileNames)
{
if (File.Exists(tempFileName))
{
File.Delete(tempFileName);
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?