看system.web.mail的说明,十分钟就可以写出来
解决方案 »
- 如何实现asp.net向一个指定的URL发送一个字符流信息
- 关于frame页面跳转的问题
- sql查询的问题
- js 隐藏和弹出窗口
- 用户自定义控件问题
- 在编辑框中写代码的时候就报错,错误对话框的第一句是:microsoft visual studio遇到了问题,需要关闭。第二行是:如果打开的文件中包含为保存的更
- 如何读取客户端的文件夹
- ?_? c# OleDbCommand.Transaction应用同时更新问题
- URL传值问题。各位高手帮帮忙
- 如何实现点击DropDownList后下面出现一个Calendar,选择日期后DropDownList中内容即为选择的日期?请高手指教。
- 文本框中数据显示问题!!!
- /*紧急*/这样的SQL语句该怎么写?
msgMail.To = "[email protected]";
msgMail.From = "[email protected]";
msgMail.Subject = "Attachment Test";
msgMail.BodyFormat = MailFormat.Text;
msgMail.Body = "Check out the attachment!";
msgMail.Attachments.Add(new MailAttachment("c:\\test.xml"));
SmtpMail.Send(msgMail);
Response.Write("Email was queued to disk");
vs2005 引用 System.Net.Mail命名空间,安全性得到了增强...
try
{
//创建邮件消息
MailMessage objMailMessage = new MailMessage();
objMailMessage.From = System.Configuration.ConfigurationSettings.AppSettings["mailfrom"];//源邮件地址"[email protected]"
objMailMessage.To = System.Configuration.ConfigurationSettings.AppSettings["mailto"];//目的邮件地址"[email protected]"
objMailMessage.Subject = "邮件的标题";//发送邮件的标题
objMailMessage.Body = "邮件的内容";//发送邮件的内容
string user = System.Configuration.ConfigurationSettings.AppSettings["mailuser"];//源邮件地址用户名
string psw = (System.Configuration.ConfigurationSettings.AppSettings["mailpsw"]);//源邮件地址用户密码
//基本权限
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//用户名
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", user) ;
//密码
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", psw);
//如果没有上述三行代码,则出现如下错误提示:服务器拒绝了一个或多个收件人地址。服务器响应为: 554 : Client host rejected: Access denied
//SMTP地址
SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSettings["mailsvr"];//"smtp.163.com"
//开始发送邮件
SmtpMail.Send(objMailMessage);
}
catch(Exception ex)
{
Log4Net.WriteLog("Exec_MailSend ERROR="+ex.ToString());
}
...
string file = "e:\xxx.rar";
MailMessage message = new System.Net.Mail.MailMessage("[email protected]", "[email protected]", "正文", "标题");
Attachment data = new System.Net.Mail.Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet);
System.Net.Mime.ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = File.GetCreationTime(file);
message.Attachments.Add(data);
SmtpClient client = new SmtpClient(server);
client.Credentials = new NetworkCredential("用户名", "密码");
client.Send(message);
data.Dispose();
client.Credentials = new NetworkCredential("用户名", "密码");
这个NetworkCredential是您自己定义的吧
给个解释啊
client.Credentials = new NetworkCredential("用户名", "密码");
这个NetworkCredential是您自己定义的吧
给个解释啊
-----------------------------------------------------------
using System.Net;
protected void Button1_Click(object sender, EventArgs e)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); msg.From = new MailAddress("[email protected]");
msg.To.Add(new MailAddress(TextBox1.Text));
msg.Subject = TextBox2.Text;
msg.Body = TextBox3.Text;
string attachFile;
attachFile=FileUpload1.FileName; System.Net.Mail.Attachment mailadd = new Attachment(FileUpload1.PostedFile.InputStream, attachFile);
msg.Attachments.Add(mailadd); SmtpClient smt = new SmtpClient();
smt.Send(msg);
}
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="收件人地址:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="216px"></asp:TextBox><br />
<br />
<asp:Label ID="Label2" runat="server" Text="主题:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="219px"></asp:TextBox><br />
<br />
<asp:Label ID="Label4" runat="server" Text="附件:"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<br />
<asp:Label ID="Label3" runat="server" Text="内容:"></asp:Label><br />
<asp:TextBox ID="TextBox3" runat="server" Height="176px" Width="348px"></asp:TextBox><br />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="发送" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="取消" /></div>
</form>
</body>
</html>然后在web.config里面配置下:
<?xml version="1.0"?>
<configuration>
<system.net>
//配置smtp
<mailSettings>
<smtp deliveryMethod="Network" from="[email protected]">
<network defaultCredentials="false" host="smtp.126.com" port="25" userName="yuzhen20" password="tramper11"/>
</smtp>
</mailSettings>
</system.net> <connectionStrings/>
<system.web>
<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
<compilation debug="true"/>
<authentication mode="Windows"/>
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>