日期:2014-05-18 浏览次数:21064 次
//要引用System.Web.Mail命名空间。引用该命名空间需要添加System.Web.Dll MailMessage mail = new MailMessage(); mail.BodyFormat=MailFormat.Html; mail.From ="some@server"; mail.To="some@server";//多个收件人之间用分号分割 mail.Bcc="some@server";//密送 mail.Cc=="some@server";//抄送 mail.Subject = "this is mail subject"; mail.Body ="this is mail body"; mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username"); mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password); System.Web.Mail.MailAttachment attachment=new MailAttachment("c:\\1.txt"); mail.Attachments.Add(attachment); SmtpMail.SmtpServer = "10.2.140.100"; SmtpMail.Send(mail);
------解决方案--------------------
楼上代码只能用于asp.net中,如果是c/s,只能封装到Web服务中,来调用实现.
------解决方案--------------------
http://blog.csdn.net/tianzhenjing/archive/2006/12/22/1454413.aspx
------解决方案--------------------
CS下同样有个发送接受邮件的命名控件using System.Net.Mail;
使用很简单,查查MSDN就行了
------解决方案--------------------
用JMAIL现成组件,什么都设计好了,设置好属性就能发了。不光能发还能收邮件。从pop3服务器里把邮件读取回来。打个广告,我资源里有,要的话去下吧。
------解决方案--------------------
http://topic.csdn.net/u/20080301/17/18568a4c-0c34-4bad-b0c5-08bc16a297ef.html
------解决方案--------------------
using System.Net.Mail;
using System.Net.Mime;
using System.Net;
public static void CreateMessageWithAttachment(string server)
{
// Specify the file to be attached and sent.
// This example assumes that a file named Data.xls exists in the
// current working directory.
string file = @"D:\asdf.txt";
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
"asdf@163.com",
"asdf@163.com",
"test",
"no du");
// Create the file attachment for this e-mail message.
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
// Add the file attachment to this e-mail message.
message.Attachments.Add(data);
//Send the message.
SmtpClient client = new SmtpClient(server);
// Add credentials if the SMTP server requires them.
//client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential("username", "password");
client.Send(message);
// Display the values in the ContentDisposition for the attachment.
ContentDisposition cd = data.ContentDisposition;
Console.WriteLine("Content disposition");
Console.WriteLine(cd.ToString());
Console.WriteLine("File {0}", cd.FileName);