csharp 发送电子邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 发送电子邮件相关的知识,希望对你有一定的参考价值。
using System.Net;
using System.Net.Mail;
public static void SendMail(string msg, string subject)
{
try
{
SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential = new NetworkCredential("user", "pass");
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("sender@address");
MailAddress toAddress1 = new MailAddress("receiver@address");
smtpClient.Host = "smtpserver";
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
message.From = fromAddress;
message.Subject = subject;
message.IsBodyHtml = false;
message.Body = msg;
message.To.Add(toAddress1);
smtpClient.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
smtpClient.SendAsync(message, "normal msg");
}
catch
{
//MessageBox.Show("Error tijdens verzenden notificatie: " + ex.Message);
}
}
private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
{
try
{
String token = (string)e.UserState;
if (e.Cancelled)
{
//
}
if (e.Error != null)
{
//
}
else
{
//
}
}
catch { }
}
以上是关于csharp 发送电子邮件的主要内容,如果未能解决你的问题,请参考以下文章
csharp 致电SMO并发送电子邮件
csharp 发送电子邮件
csharp 发送电子邮件
csharp 发送电子邮件
csharp 再次发送电子邮件模板 - 拉动公司设置
csharp 使用链接方法模式使用C#.NET发送电子邮件