欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# 发送电子邮件源码片段

程序员文章站 2022-03-23 19:22:22
下面代码内容是关于C# 发送电子邮件片段的代码,应该对各位有所用途。 using System;using System.Web;using System.Web.Mail;public class TestSendMail{ public static void Main() { try { Ma ......

下面代码内容是关于c# 发送电子邮件片段的代码,应该对各位有所用途。

using system;
using system.web;
using system.web.mail;
public class testsendmail
{
public static void main()
{
try
{
mailmessage message = new mailmessage();
message.from = from@domain.com;
message.to = pengyun@cobainsoft.com;
message.cc = ;
message.bcc = ;
message.subject = subject;
message.body = content of message;

message.attachments.add(new mailattachment(c:\attach.txt, mailencoding.base64));

smtpmail.send(message);
system.console.writeline(message has been sent);
}
catch(exception ex)
{
system.console.writeline(ex.message.tostring());
}
}
}