win form 下怎么样用C#来发送邮件?? win form 下怎么样用C#来发送邮件??win form 情况下 C#里面好像没有vb的发邮件功能简单,哪位知道怎么发送????????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 namespace CdoSys{ using System; class Class1 { static void Main(string[] args) { try { CDO.Message oMsg = new CDO.Message(); CDO.Configuration iConfg = new CDO.Configuration(); ADODB.Fields oFields; ADODB.Field oField; oFields = iConfg.Fields; oField =oFields["http://schemas.microsoft.com/cdo/configuration/smtpsserver"];oField.Value = "smarthost"; oField =oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];oField.Value =25; oFields.Update(); oMsg.Configuration = iConfg; // Set common properties for Message oMsg.Subject = "Test SMTP"; oMsg.From = "[email protected]"; oMsg.To = "[email protected]"; oMsg.Send(); } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); } return; } }} 用Mail类,到搜索网站www.baidu.com搜索一下:"C# Main 发送邮件" C#中有一个Email的类。不过不太好使,要用自己的邮件服务器。一般的邮件服务器都需要验证的。 http://helloworld84.cnblogs.com/archive/2005/09/02/229063.html 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.Send(em); return true; } catch { return false; } } } using System.Web.MailMailMessage mm = new MailMessage();mm.Body = "";mm.** ="";Smtp*** .Send(mm); 爬虫如何获取执行完js后的html源文件 如何将从父窗口获取的值 赋予子窗口的某个控件? 一个事件问题 小问题,关于字符串中的参数问题 请教一下,怎么每次实例化后都要去执行一下 从数据库读取数据到listbox里面 用FOR循环 gdi+ 调整图片亮度和对比度 方法参数ref,out的问题! 创建WCF服务并部署到IIS,访问服务器出现错误。 手机短信问题 望高手指点下 用C#写的com组件负责数据库连接,如何让数据库连接持久化? 数据绑定及DataGrid应用
{
using System;
class Class1
{
static void Main(string[] args)
{
try
{
CDO.Message oMsg = new CDO.Message();
CDO.Configuration iConfg = new CDO.Configuration();
ADODB.Fields oFields;
ADODB.Field oField; oFields = iConfg.Fields;
oField =
oFields["http://schemas.microsoft.com/cdo/configuration/smtpsserver"];
oField.Value = "smarthost"; oField =
oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
oField.Value =25; oFields.Update(); oMsg.Configuration = iConfg; // Set common properties for Message
oMsg.Subject = "Test SMTP";
oMsg.From = "[email protected]";
oMsg.To = "[email protected]"; oMsg.Send();
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
return;
}
}
}
不过不太好使,要用自己的邮件服务器。
一般的邮件服务器都需要验证的。
{
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.Send(em);
return true;
}
catch
{
return false;
}
}
}
mm.Body = "";
mm.** ="";
Smtp*** .Send(mm);