c#每日一题(七)

VBDN 2005-04-07 09:26:36
使用SmtpMail类发一份邮件到9755445@sohu.com(发送成功即可,别滥发。)
...全文
591 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiezic 2005-04-14
  • 打赏
  • 举报
回复
留意
wangasp 2005-04-14
  • 打赏
  • 举报
回复
进行到底
jb303 2005-04-09
  • 打赏
  • 举报
回复
up
xiongchen 2005-04-09
  • 打赏
  • 举报
回复
楼主是个热心人,希望楼主一直坚持下去,将贴子搞成一个系列!
强烈建议班主置顶!
VBDN 2005-04-08
  • 打赏
  • 举报
回复
有谁能解释一下egxsun()的代码中“AdminEmail”域的用处?
VBDN 2005-04-08
  • 打赏
  • 举报
回复
System.Web.Mail是Web Application中才有的namespace,应该创建一个web项目,上面几位是不是winform或console的阿
==================================================================================
winform和Console里同样可用System.Web.Mail
awperpvip 2005-04-08
  • 打赏
  • 举报
回复
up...
aprex 2005-04-07
  • 打赏
  • 举报
回复
我也是 啊
mabuchi 2005-04-07
  • 打赏
  • 举报
回复
up
freddy2003 2005-04-07
  • 打赏
  • 举报
回复
为什么这一句总是有错呢?

using System.Web.Mail;
freddy2003 2005-04-07
  • 打赏
  • 举报
回复
TO egxsun():

编译有错!!

D:\Documents and Settings\Administrator\My Documents\ConsoleApplication1\Class1.cs(2): 类型或命名空间名称“Mail”在类或命名空间“System.Web”中不存在(是否缺少程序集引用?)
freddy2003 2005-04-07
  • 打赏
  • 举报
回复
up
panzh10 2005-04-07
  • 打赏
  • 举报
回复
up
conan19771130 2005-04-07
  • 打赏
  • 举报
回复
好像越来越难了,好,顶
thundersoft 2005-04-07
  • 打赏
  • 举报
回复
System.Web.Mail是Web Application中才有的namespace,应该创建一个web项目,上面几位是不是winform或console的阿
Matthewzhong 2005-04-07
  • 打赏
  • 举报
回复
To ybb575(ybb)
发送信件的时候SMTP服务器要验证用户的有效身份
那三句就是用来验证用户有效性的
如果你使用的SMTP服务器是不需要验证的话那三句话就可以省略不写
egxsun 2005-04-07
  • 打赏
  • 举报
回复
using System;
using System.Web.Mail;

/// SystemMail 的摘要说明。

///

public class SystemMail

{

private string _adminEmail;

private string _smtpServer = "localhost";

private string _password;

private string _userName;



public SystemMail()

{

}





public string AdminEmail

{

get{return _adminEmail;}

set{_adminEmail = value;}

}





public string SmtpServer

{

get{return _smtpServer;}

set{_smtpServer = value;}

}





public string Password

{

get{return _password;}

set{_password = value;}

}





public string UserName

{

get{return _userName;}

set{_userName = value;}

}



public bool Send(string to, string from, string subject, string message)

{

try

{

MailMessage em = new MailMessage();

em.To = to;

em.From = from;

em.Subject = subject;

em.Body = message;



//Found out how to send authenticated email via System.Web.Mail at http://SystemWebMail.com (fact 3.8)

if(this.UserName != null && this.Password != null)

{

em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication

em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this.UserName); //set your username here

em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.Password); //set your password here

}



SmtpMail.SmtpServer = this.SmtpServer;
// SmtpMail.SmtpServer = "smtp.126.com";

SmtpMail.Send(em);

return true;

}

catch

{

return false;

}

}



}
qiqiyi 2005-04-07
  • 打赏
  • 举报
回复
up
qdcax 2005-04-07
  • 打赏
  • 举报
回复
up
不是很明白!
wingnal 2005-04-07
  • 打赏
  • 举报
回复
这能好一点了
加载更多回复(2)

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧