我用的是VS2008
哪位写过 C/S 发邮件的程序
我找过很多方法,但都提示发邮件失败其中一个例子:
SmtpClient client = new SmtpClient("192.168.0.1");
client.Credentials = new NetworkCredential("[email protected]", "pwd");
MailMessage msg = new MailMessage("[email protected]", "[email protected]");
msg.Subject = "HELLO";
msg.Body = "Body";
client.Send(msg);
哪位写过 C/S 发邮件的程序
我找过很多方法,但都提示发邮件失败其中一个例子:
SmtpClient client = new SmtpClient("192.168.0.1");
client.Credentials = new NetworkCredential("[email protected]", "pwd");
MailMessage msg = new MailMessage("[email protected]", "[email protected]");
msg.Subject = "HELLO";
msg.Body = "Body";
client.Send(msg);
{ string Postername = "xxx"; //发送者邮箱地址
string PosterPwd = "xxx";//发送者邮箱密码
string SmtpHost = "smtp.gmail.com";//发送服务器 string getstr = "";
global::System.Net.Mail.MailMessage mailmsg = new System.Net.Mail.MailMessage();
//定义发件人
mailmsg.From = new MailAddress(Poster);
//添加收件人
mailmsg.To.Add(RequestEmail);
//邮件标题
mailmsg.Subject = "本邮件由xxx发送";
mailmsg.IsBodyHtml = false; //邮件内容
mailmsg.Body = DateTime.Now.ToLongDateString();
if (!string.IsNullOrEmpty(attachfile))
{
mailmsg.Attachments.Add(new Attachment(attachfile));
mailmsg.Body += "\r\n send from xxx";
}
//默认为html格式邮件
//mailmsg.IsBodyHtml = true; SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = 25;
smtpClient.Host = SmtpHost;
smtpClient.Credentials = new NetworkCredential("xxxx", "xxx");
try
{
smtpClient.SendAsync(mailmsg);
getstr = "发送成功";
} catch (SmtpException s)
{
getstr = s.Message;
}
return getstr;
}