求一个发送邮件的代码,邮件内容是网页 (我用的是.net2003) 急求,我测试了一个,直接在对方邮件里显示的 <html> <body> <iframe src="http://www.xxx.com/xx.aspx" ></iframe> </body> </html>求一个.net 1.1 版本的能发送个网页的代码,2.0和以上的代码就不用了,1.1下不好使 .谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 邮件正文最好不要用iframe,好多邮件服务器都过滤他,担心iframe网页有毒 public static bool sendMail(string to, string from, string subject, string message) { System.Web.Mail.MailMessage Message = new System.Web.Mail.MailMessage(); Message.To = to.Replace(",", ";"); Message.From = from; Message.Subject = subject; Message.Body = message; Message.BodyFormat = System.Web.Mail.MailFormat.Html; Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);//基本权限 Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username");//用户名 Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");//密码 Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25); Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendserver", "smtp.sina.com"); Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", false);//SSL try { System.Web.Mail.SmtpMail.Send(Message); return true; } catch { return false; } } Message.BodyFormat = System.Web.Mail.MailFormat.Html;加上这句即可如果你要发送<iframe> or <script>恐怕不行,安全过滤 jmail.Message j = new jmail.Message(); String Subject = ""; String body = "" ; String FromEmail = "[email protected]"; String ToEmail = dr["Email"].ToString(); j.Silent = true; j.Logging = true; j.ContentType = "text/html"; j.AddRecipient(ToEmail, "", ""); j.From = FromEmail; j.MailServerUserName = ""; j.MailServerPassWord = "123456"; j.Subject = Subject; j.Body = body + "<br>"+t.ToString(); j.Send("smtp.163.com", false); j.Close(); iframe可能禁止 楼上的方法可以了,既然是网页就要选html模式,内容自己拼写或直接读取个模板下面一个读取模板发送的的例子,一般模板做些标记标记,之后替换内容,另外发送到邮箱的网页不要用JS,iframe另外css也要写在页里面,不要引用,图片的src要加上全路径,邮箱里是不是自动找到你服务器里的图片的,如<img src="http://www.123.com/images/001.gif" width="190" height="95">不能写成<img src="images/001.gif" width="190" height="95">string str=""; Encoding code=Encoding.GetEncoding("gb2312"); string temp=Server.MapPath("html/1.html"); //模板页放在html下的1.html StreamReader sr=null; //读取模板 try { sr=new StreamReader(temp,code); str=sr.ReadToEnd(); } catch(Exception exp) { Response.Write(exp.Message); Response.End(); sr.Close(); } sr.Close();//下面这2个是在网页里做的标记,我的是发新闻,myTitle,myText好 2个字段是放新闻标题和内容的 //str=str.Replace("myTitle","测试标题-防爆电器测试"); //str=str.Replace("myText","测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试"); MailMessage message = new MailMessage(); message.To = "[email protected]"; message.Priority = MailPriority.High; message.From = "[email protected]"; message.Subject = "标题"; message.BodyFormat = MailFormat.Html; message.Body = str; message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "用户用"); message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "密码"); SmtpMail.SmtpServer = "smtp.163.com"; try { SmtpMail.Send(message); base.Response.Write("<script>alert('提交成功!')</script>"); } catch { base.Response.Write("<script>alert('提交失败!')</script>"); } 少说了3引用using System.Web.Mail; using System.Text;using System.IO; 请问,如何设置另外一个进程的SysDateTimePick32控件的日期? C#类,跪求帮助 datagridview 数据更新后行选择问题 急急急急急急急 如何得到只读的文本框? 请问一下,有没有什么办法把EXCEL表格嵌入到WinForm中,然后进行操作啊? winform里可以使用HtmlEncode这个函数吗? 我在C#中写一个类。继承至SOCKET类 我想像VC里一样重写OnReceive这个函数。。怎么做? 关于捕捉扫描枪事件 高分求助,文件显示 怎样才能使Label像TextBox那样可以输入数据 关于颜色
public static bool sendMail(string to, string from, string subject, string message)
{
System.Web.Mail.MailMessage Message = new System.Web.Mail.MailMessage();
Message.To = to.Replace(",", ";");
Message.From = from;
Message.Subject = subject;
Message.Body = message;
Message.BodyFormat = System.Web.Mail.MailFormat.Html;
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);//基本权限
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username");//用户名
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");//密码
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendserver", "smtp.sina.com");
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", false);//SSL
try
{
System.Web.Mail.SmtpMail.Send(Message);
return true;
}
catch
{
return false;
}
}
加上这句即可如果你要发送<iframe> or <script>恐怕不行,安全过滤
String Subject = "";
String body = "" ;
String FromEmail = "[email protected]";
String ToEmail = dr["Email"].ToString();
j.Silent = true;
j.Logging = true;
j.ContentType = "text/html";
j.AddRecipient(ToEmail, "", "");
j.From = FromEmail;
j.MailServerUserName = "";
j.MailServerPassWord = "123456";
j.Subject = Subject;
j.Body = body + "<br>"+t.ToString();
j.Send("smtp.163.com", false);
j.Close();
iframe可能禁止
下面一个读取模板发送的的例子,一般模板做些标记标记,之后替换内容,另外发送到邮箱的网页不要用JS,iframe
另外css也要写在页里面,不要引用,图片的src要加上全路径,邮箱里是不是自动找到你服务器里的图片的,如
<img src="http://www.123.com/images/001.gif" width="190" height="95">不能写成
<img src="images/001.gif" width="190" height="95">string str="";
Encoding code=Encoding.GetEncoding("gb2312");
string temp=Server.MapPath("html/1.html"); //模板页放在html下的1.html
StreamReader sr=null;
//读取模板
try
{
sr=new StreamReader(temp,code);
str=sr.ReadToEnd();
}
catch(Exception exp)
{
Response.Write(exp.Message);
Response.End();
sr.Close();
}
sr.Close();
//下面这2个是在网页里做的标记,我的是发新闻,myTitle,myText好 2个字段是放新闻标题和内容的
//str=str.Replace("myTitle","测试标题-防爆电器测试");
//str=str.Replace("myText","测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试测试一些产品的信息我就测试");
MailMessage message = new MailMessage();
message.To = "[email protected]";
message.Priority = MailPriority.High;
message.From = "[email protected]";
message.Subject = "标题";
message.BodyFormat = MailFormat.Html;
message.Body = str;
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "用户用");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "密码");
SmtpMail.SmtpServer = "smtp.163.com";
try
{
SmtpMail.Send(message);
base.Response.Write("<script>alert('提交成功!')</script>");
}
catch
{
base.Response.Write("<script>alert('提交失败!')</script>");
}
using System.Text;
using System.IO;