C#中的怎么用代码实现MAIL的发送..

a380151346 2008-07-14 11:42:55
C#中的怎么用代码实现MAIL的发送..好想在F2.0中改成了System.NET.MAIL(类名)..那位高人可以讲解下...最好有完整的代码实例..先谢了..
...全文
141 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ericzhangbo1982111 2008-07-14
  • 打赏
  • 举报
回复
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();

client.Host = "mail.bcl.com.cn";
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("zhangbo@mail.bcl.com.cn", "111111");
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("zhangbo@mail.bcl.com.cn", "zhangbo@mail.bcl.com.cn");
message.Subject = "测试aa";
message.Body = "<html>用自己写的asdfasdf软件发的邮件!<image src=1.jpg></image></html>";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
message.Attachments.Add(new Attachment("C:\\1.jpg"));

////添加附件
//Attachment data = new Attachment(@"附件地址如:e:\a.jpg", System.Net.Mime.MediaTypeNames.Application.Octet);
//message.Attachments.Add(data);








try
{
client.Send(message);

}
catch (Exception ex)
{ }
lawbc 2008-07-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 cad502 的回复:]
刚好学习 System.Net.Mail

以下代码经过测试成功


private void button1_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.Subject = textBox1.Text;
msg.Body = textBox2.Text;
msg.From = new MailAddress("发送邮件帐号"); //
msg.To.Add(new MailAddress("接受邮件的帐号"));
Smt…
[/Quote]
冬天的糊涂神 2008-07-14
  • 打赏
  • 举报
回复
刚好学习 System.Net.Mail

以下代码经过测试成功



private void button1_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.Subject = textBox1.Text;
msg.Body = textBox2.Text;
msg.From = new MailAddress("发送邮件帐号"); //
msg.To.Add(new MailAddress("接受邮件的帐号"));
SmtpClient c = new SmtpClient();
c.Host = "发送邮件服务器";
c.Credentials = new System.Net.NetworkCredential("发送邮件帐号", "发送邮件的邮箱密码");
c.Send(msg);
}
贫僧又回来了 2008-07-14
  • 打赏
  • 举报
回复
还有jmail也可以!网上摘录!
首先,下载jmail组件,可以直接安装;也可以找到jmail.dll,手动注册组件。命令行环境下,到jmail.dll所在目录,运行regsvr32 jmail.dll,C#程序中,行首加上using jmail,如下:(点击btnSend按钮后发送邮件)
using jmail;

private void btnSend_Click(object sender, System.EventArgs e)
{
jmail.Message jmessage=new jmail.MessageClass();
jmessage.Charset="GB2312";
jmessage.From="fromuser@benq.com";
jmessage.FromName= "eric lv" ;
jmessage.ReplyTo="replayto@benq.com";
jmessage.Subject="test email from jmessage";
jmessage.AddRecipient("receiver@benq.com" ,"eric lv","123");
jmessage.Body= "jmail 内容" ;
jmessage.MailServerUserName= "eric lv" ;
jmessage.MailServerPassWord= "user password" ;
jmessage.Send("smtp-server",false) ;
MessageBox.Show("email sent successfully!");
jmessage.Close() ;
}

niitnanfeng 2008-07-14
  • 打赏
  • 举报
回复
好多好多。
beancurd005 2008-07-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 Guyschaos 的回复:]
C# code MailMessage mail = new MailMessage();
mail.To.Add("XXXXX@163.com");
mail.From = new MailAddress("XXXXX@163.com", "XXXXX", Encoding.UTF8);
mail.Subject = "test";
mail.SubjectEncoding = Encoding.UTF8;
mail.Body = "testmail";
mail.BodyEncoding = Encoding.UTF8;
mail.IsBodyHtml = false;

[/Quote]
a380151346 2008-07-14
  • 打赏
  • 举报
回复
还有吗??嘿嘿
贫僧又回来了 2008-07-14
  • 打赏
  • 举报
回复
            MailMessage mail = new MailMessage();
mail.To.Add("XXXXX@163.com");
mail.From = new MailAddress("XXXXX@163.com", "XXXXX", Encoding.UTF8);
mail.Subject = "test";
mail.SubjectEncoding = Encoding.UTF8;
mail.Body = "testmail";
mail.BodyEncoding = Encoding.UTF8;
mail.IsBodyHtml = false;
mail.Priority = MailPriority.High;

//SMTP
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("username", "password");
client.Host = "smtp.163.com";
object userState = mail;

try
{
client.Send(mail);
Console.WriteLine("Successful");
}
catch (SmtpException ex)
{
Console.WriteLine("Err: " + ex.Message);
}
a380151346 2008-07-14
  • 打赏
  • 举报
回复
还有吗??

110,963

社区成员

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

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

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