请教:.net中如何发送电子邮件? 问题如下: 如何用.NET开发邮件发送功能的模块? 就是有什么类,用什么方法可以把一段文字以电子邮件的形式发送到指定的IP上? 谢谢. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是的.我再说的仔细些.要我开发一个系统: 用户把某个文件传送到几个同事处,方法就是发电子邮件告诉他们文件在啊里, 所以现在的问题就是在ASP.NET中用什么代码能把一封自定义的邮件发出去. 自己写的话,用System.Web.Mail中。MSDN上有示例要现在所写好的。我这里有,发给你一份吧。或者在论坛上搜一下前几天有发过的。我就是里从那里下载的。。 using System.Web.Mail ; private void SendButton_Click(object sender, System.EventArgs e) { try { MailMessage Message = new MailMessage ( ) ; //新建一个MailMessage对象 Message.From = textBox1.Text ; //定义发信人地址 Message.To = textBox2.Text ; //定义收信人地址,如果是多人,可以用“,”分开 Message.Subject = textBox3.Text ; //定义邮件的主题 Message.Body = textBox4.Text ; //定义邮件的内容 if ( openFileDialog1.FileName != "" ) { MailAttachment Attachment = new MailAttachment ( openFileDialog1.FileName ,MailEncoding.Base64 ) ; //以Base64编码创建一个附件实例 Message.Attachments.Add ( Attachment ) ; //给邮件增加附件 } //判断要发送的邮件是否有附件,如果有则加入 SmtpMail.Send ( Message ) ; //发送电子邮件 MessageBox.Show( "电子邮件已经发送到->" + textBox2.Text ) ; } catch ( Exception ex ) { MessageBox.Show ( ex.Message.ToString ( ) ) ; } } public void CDOsendMail(){ try { CDO.Message oMsg = new CDO.Message(); oMsg.From = "[email protected]"; oMsg.To = "[email protected]"; oMsg.Subject = "MailTest"; oMsg.HTMLBody = "<html><body>Test</body></html>"; CDO.IConfiguration iConfg = oMsg.Configuration; ADODB.Fields oFields = iConfg.Fields; oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value=2;oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value="[email protected]"; //sender mailoFields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value="[email protected]"; //email accountoFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value="username";oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value="password"; oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;//value=0 代表Anonymous验证方式(不需要验证)//value=1 代表Basic验证方式(使用basic (clear-text) authentication. //The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)//Value=2 代表NTLM验证方式(Secure Password Authentication in Microsoft Outlook Express)oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804;oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value="smtp.21cn.com"; oFields.Update(); oMsg.BodyPart.Charset="gb2312"; oMsg.HTMLBodyPart.Charset="gb2312"; oMsg.Send(); oMsg = null; } catch (Exception e) { throw e; }} 编译错误!急! C#用户登录验证能获取库中的名和密码,但不管密码对错都不能登录成功,新手望高手指教修改具体代码和位置 Asp。net中锚点是怎么做的 使用中文做文件或目录名时,造成的错误,如何解决..谢谢 请问CSDN论坛“载入中……”这种效果怎么实现? Jmail发送时出现的奇怪问题! 网站向手机的短信发送 触发不了单击事件 又有问题了,怎么把null值插入表里的int字段? 文件系统转换后出现的问题 我发的邮件为什么总是失败??? 下面发送邮件的代码,为什么出错?在线等ing……
我再说的仔细些.
要我开发一个系统:
用户把某个文件传送到几个同事处,方法就是发电子邮件告诉他们文件在啊里,
所以现在的问题就是在ASP.NET中用什么代码能把一封自定义的邮件发出去.
前几天有发过的。我就是里从那里下载的。。
{
try
{
MailMessage Message = new MailMessage ( ) ;
//新建一个MailMessage对象
Message.From = textBox1.Text ;
//定义发信人地址
Message.To = textBox2.Text ;
//定义收信人地址,如果是多人,可以用“,”分开
Message.Subject = textBox3.Text ;
//定义邮件的主题
Message.Body = textBox4.Text ;
//定义邮件的内容
if ( openFileDialog1.FileName != "" )
{
MailAttachment Attachment = new MailAttachment ( openFileDialog1.FileName ,MailEncoding.Base64 ) ;
//以Base64编码创建一个附件实例
Message.Attachments.Add ( Attachment ) ;
//给邮件增加附件
}
//判断要发送的邮件是否有附件,如果有则加入
SmtpMail.Send ( Message ) ;
//发送电子邮件
MessageBox.Show( "电子邮件已经发送到->" + textBox2.Text ) ;
}
catch ( Exception ex )
{
MessageBox.Show ( ex.Message.ToString ( ) ) ;
}
}
{
try
{
CDO.Message oMsg = new CDO.Message();
oMsg.From = "[email protected]";
oMsg.To = "[email protected]";
oMsg.Subject = "MailTest";
oMsg.HTMLBody = "<html><body>Test</body></html>"; CDO.IConfiguration iConfg = oMsg.Configuration;
ADODB.Fields oFields = iConfg.Fields;
oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value=2;
oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value="[email protected]"; //sender mail
oFields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value="[email protected]"; //email account
oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value="username";
oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value="password";
oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;
//value=0 代表Anonymous验证方式(不需要验证)
//value=1 代表Basic验证方式(使用basic (clear-text) authentication.
//The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)
//Value=2 代表NTLM验证方式(Secure Password Authentication in Microsoft Outlook Express)
oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804;
oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value="smtp.21cn.com"; oFields.Update();
oMsg.BodyPart.Charset="gb2312";
oMsg.HTMLBodyPart.Charset="gb2312"; oMsg.Send();
oMsg = null;
}
catch (Exception e)
{
throw e;
}
}