- 方法一: 通过SmtpClient 对象来发送邮件
SmtpClient smtpClient = new SmtpClient("2.com");
smtpClient.Credentials = new System.Net.NetworkCredential("1@2.com", "pwd");
smtpClient.UseDefaultCredentials = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("1@2.com");
mail.To.Add(new MailAddress("1@2.com"));
smtpClient.Send(mail);
- 方法二:借助Outlook来发送(需要借助:Microsoft.Office.Interop.Outlook.dll)
using Outlook = Microsoft.Office.Interop.Outlook; Outlook.Application app = new Outlook.Application(); Outlook.MailItem mailItem = app.CreateItem(Outlook.OlItemType.olMailItem); mailItem.Subject = "Test"; mailItem.To = "1@2.com"; mailItem.Body = "This is the message."; mailItem.Attachments.Add(attachment);//此处的attachment是附件的地址。 mailItem.Display(false); mailItem.Send();