今天在网上搜索了一上午,发现例子很多但是很多是不能用的,我现在把代码如下,希望告诉哪里错了,而不是直接贴代码,解决以后一定给分,谢谢!
using System.Web.Mail;
MailMessage mail = new MailMessage();
mail.From="[email protected]";
mail.To="[email protected]";
mail.Subject="this is a email";
mail.Body="Some text as goes here";
mail.BodyFormat=MailFormat.Html;
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "aount
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "pwd
SmtpMail.SmtpServer="smtp.sina.com";
SmtpMail.Send(mail);
using System.Web.Mail;
MailMessage mail = new MailMessage();
mail.From="[email protected]";
mail.To="[email protected]";
mail.Subject="this is a email";
mail.Body="Some text as goes here";
mail.BodyFormat=MailFormat.Html;
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "aount
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "pwd
SmtpMail.SmtpServer="smtp.sina.com";
SmtpMail.Send(mail);
解决方案 »
- 网页怎么转成Word文档,大家讨论一下
- webResponse.Close();
- Ling to SQL中如何实现非级联插入
- 注册界面上,点击DropDownList后,输入密码的文本框变为空了
- web窗体怎样跳转到windows窗体啊?
- ASP.NET是否要掌握C#
- 求助,急求找回软件登录密码的方法!
- 如何实现有消息时的声音提示功能
- 做过aspx添加新闻页面并且使用ubb.inc的大侠请进!
- 如何用C#代码解密内嵌有小图片的二维码
- javascript动态添加/删除表格数据行,如何把这个动态表格里的每行都添加数据库,并且如何能实现从数据库读取后能加载到动态表格里.
- 如何实现想淘宝那样的(拼音检索汉字)检索功能
mm.To.Add(new MailAddress("[email protected]"));
mm.From = new MailAddress("[email protected]");
mm.Subject = "this is a email";
mm.Body = "Some text as goes here";
mm.BodyEncoding = System.Text.Encoding.UTF8;
System.Net.Mail.SmtpClient aa = new System.Net.Mail.SmtpClient();
aa.Host = "smtp.sina.com.cn";
aa.Port = 25;
aa.Credentials = new System.Net.NetworkCredential("aount", "pwd");//验证发信人
aa.DeliveryMethod = SmtpDeliveryMethod.Network;
aa.Send(mm);--试试这段
2、不知道你有沒有裝smtp
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "pwd
括号都不对称。。
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;public partial class _Default : System.Web.UI.Page
...{
int i = 0;
protected void Page_Load(object sender, EventArgs e)
...{
}
protected void Button1_Click(object sender, EventArgs e)
...{
string s_from = TextBox1.Text.Trim().ToString();//发件人
string s_to = TextBox2.Text.Trim().ToString();//收件人
string s_body = TextBox4.Text.Trim().ToString();//邮件内容
s_body = s_body.Replace(" ", "<br/>");
s_body = s_body.Replace(" ", "<br/>");
s_body = s_body.Replace(" ", " "); int i = s_from.IndexOf("@");
string username = s_from.Substring(0, i);
MailAddress from = new MailAddress(s_from);
MailAddress to = new MailAddress(s_to);
MailMessage mailobj = new MailMessage(from, to);
mailobj.Subject = TextBox3.Text.Trim().ToString();//邮件标题
mailobj.Body = s_body;
mailobj.IsBodyHtml = true;
mailobj.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
mailobj.Priority = MailPriority.High; if (FileUpload1.PostedFile.ContentLength > 0)//附件
...{
mailobj.Attachments.Add(new Attachment(FileUpload1.PostedFile.FileName));
} SmtpClient smtp = new SmtpClient("smtp.qq.com");
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("270332289","f5sd1e");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; try
...{
smtp.Send(mailobj);
Response.Write("ok!"); }
catch
...{
Response.Write("sorry!");
}
}
}
这个没有问题 你看看 测试过的
提供用于使用 Windows 2000 的协作数据对象 (CDOSYS) 消息组件来发送消息的属性和方法。建议使用的替代项:System.Net.Mail。
public static void CreateTestMessage1(string server, int port)
{
string to = "[email protected]";//收件人
string from = "[email protected]";//收件人
string subject = "Using the new SMTP client.";//主题
string body = @"Using this new feature, you can send an e-mail message from an application very easily.";//邮件内容
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient(server, port);
client.Credentials =new NetworkCredential(username,password);//登录邮件服务器的用户名和密码 client.Send(message);//发送邮件
}你的办法一来过时了,而来利用外部的邮件服务器发送邮件的时候需要对身份进行验证。
不知道什么SMTP是什么
在装IIS的时候SMTP不时同时安装的吗
在NET下没有Mail这个包
在按钮触发下发送邮件
MailAddress From = new MailAddress("发送人邮件地址");
MailAddress To = new MailAddress("接收人邮件地址"); MailMessage message= new MailMessage(From,To);
message.Subject = "邮件标题";
message.Body = "邮件内容";SmtpClient Client = new SmtpClient("smtp.xxx.com");
client.Send(message);
.netframework的版本是?
mail.Body = "尊敬的会员您好,您的密码为:" + dt.Rows[0]["PassWord"].ToString();
mail.From = "[email protected]";
mail.To = this.txtMail.Text.Trim().ToString();
mail.BodyFormat = MailFormat.Text;
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "[email protected]");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "19850305");
SmtpMail.SmtpServer = "smtp.tom.com";
SmtpMail.Send(mail);
string strMail=txtMail.Text.Trim();//邮件接收地址
MailMessage mailMsg=new MailMessage();
//收件人地址
mailMsg.To=strMail;
mailMsg.From="[email protected]";
//邮件主题
mailMsg.Subject="主题";
//正文
mailMsg.Body="正文";
//正文的文件类型
mailMsg.BodyFormat=MailFormat.Html;
//mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");
//mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","aaa");
//mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","");
try
{
// SmtpMail.SmtpServer="smtp.163.com";
SmtpMail.Send(mailMsg);
//SmtpMail.send("邮件源地址","邮件目标地址","邮件主题","邮件内容")
//
Response.Write("<script language='javascript'>window.alert('已发送!');</script>");
}
catch(Exception)
{
Response.Write("<script language='javascript'>window.alert('发送失败!');</script>");
}
//创建一个新的邮件
jmail.MessageClass message = new jmail.MessageClass();
//设置邮件的编码格式为中文
message.Charset = "gb2312";
//邮件的发送者
message.From = "[email protected]";
//邮件的发送者显示的名字
message.FromName = "aaaa";
//邮件的主题
message.Subject = "主题";
//邮件的内容
message.Body = "邮件正文";
//邮件服务器的验证名称和密码
message.MailServerUserName = "aaaa";
message.MailServerPassWord = "bbbb";
message.ContentType = "text/html";
//邮件接收人
message.AddRecipient("[email protected]", "aaaa", null);
message.Send("smtp.163.com", false);
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage objMessage = new MailMessage();
objMessage.From = "[email protected]";
objMessage.To = "[email protected]";
objMessage.Subject = "Test";
objMessage.Body = "E_Mail Send Success!";
objMessage.BodyFormat=MailFormat.Html;
objMessage.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
objMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "login_name");
objMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "login_pwd");
SmtpMail.SmtpServer = "smtp.sina.com.cn";
SmtpMail.Send(objMessage);
Response.Write("<script>alert('发送邮件成功!')</script>");
}
这样是没有问题的,然后你再看看你的stmp配置了没有。
建议采用System.Net.Mail下的邮件发送方法.
另外注意理解各个参数的配置意思.你的邮件发送失败我看可能是你参数理解错误.
另外杀毒软件又是一个非常大且容易被忽视的失败原因.
对后者这个原因我也是花了很久在偶然经验下才发现的.
请注意杀毒软件配置.特别是卖咖啡也开放25端口中的某些进程.否则会发生提示软件限制异常等.
祝你好运.
iis->smpt右键属性->"全部"选项卡,把自己的IP添加上->第二个选项卡中的“中断”->添加你的IP为允许。就OK了。
http://blog.csdn.net/jihuomima/archive/2008/01/23/2061711.aspx
在vs2003或2005里的命令提示中输入:tlbimp e:\jmail.dll (这是下载的dll存放地址) /out:myJmail.dll (这是生成后的dll名称) /namespace:jmail (这是要调用的命名空间名称) ,输入完这些后按回车执行,执行后会在C:\Documents and Settings\Administrator 下生成的那个新的dll 这个路径不是绝对的,要看登陆系统用的是哪个用户.
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;/// <summary>
/// YueSaiMail 的摘要说明
/// </summary>
namespace YueSai.YueSaiMail
{
public class YueSaiMail
{
public YueSaiMail()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static int SandMail()
{
int result = 0;
try
{
SmtpClient smtp = new SmtpClient();
MailMessage mail = new MailMessage();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Host = "邮件服务器地址";
smtp.Credentials = new System.Net.NetworkCredential("发送邮件的帐号", "密码!");
mail.From = new MailAddress("发送邮件人的仗号");
mail.To.Add(接受人的邮箱);
mail.Subject = "//标题";
mail.Body = 主题;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.Normal; smtp.Send(mail);
result = 1; 返回 1 发送成功
}
catch (Exception ex)
{
result = 2; 2 失败
} return result;
}
}
}
http://topic.csdn.net/u/20080413/16/07394a9d-2573-44ed-aa4c-1088cb874efb.html
我什么都拿上去了
asp.net 2.0建议你使用新的构造
http://www.cnblogs.com/hooyes/archive/2008/05/15/hooyes_DontSendMail.html