1、新建一个项目文件
2、添加引用系统目录下的cdosys.dll文件,在引用中会发现添加了两个要用到的接口:cdo,adodb
3、添加新项文件sendmail.aspx,在其页面上放置三个label,三个textbox,作用分别为收件人地址、主题、内容,放置一个button按钮。
4、切换到代码页,创建一下内容
public void cdosendmail()
{
try
{
cdo.message msg = new cdo.message();
msg.from = "rattlesnake@263.net";
msg.to = this.textbox1.text.trim();
msg.subject = this.textbox2.text.trim();
msg.htmlbody = "<html><body>"+this.textbox3.text+"</body></html>";
cdo.iconfiguration config = msg.configuration;
adodb.fields ofields = config.fields;
ofields["http://schemas.microsoft.com/cdo/configuration/sendusing"].value = 2;
ofields["http://schemas.microsoft.com/cdo/configuration/sendusername"].value="rattlesnake";
ofields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].value="pass";
ofields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].value=1;
ofields["http://schemas.microsoft.com/cdo/configuration/languagecode"].value=0x0804;
ofields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].value="smtp.263.net";
ofields.update();
msg.bodypart.charset = "gb2312";
msg.htmlbodypart.charset = "gb2312";
msg.send();
msg = null;
}
catch(exception err)
{
throw err;
}
}
5、为button添加click事件
private void button1_click(object sender, system.eventargs e)
{
this.cdosendmail();
}
运行程序即可。