用.net写了个邮件发送的测试代码,却总是无法发送,也看不到出错消息
用.net写了个邮件发送的测试代码,却总是无法发送,也看不到出错消息,而且是几乎一点发送就立刻提示发送失败,所以怀疑不是邮件服务器问题。估计是代码有问题或是.net中提供或依赖的某种服务未能正常工作,求各位高手帮忙看一下。代码如下:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Net;
using System.Net.Mail;
private void button2_Click(object sender, EventArgs e)
{
SmtpClient smtpClient = new SmtpClient();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Host = "smtp.163.com";
smtpClient.Credentials = new System.Net.NetworkCredential("userName", "Pwd");//用户名和密码
String body = "Test";
MailMessage mailMessage = new MailMessage("userName@163.com", "38051419@qq.com");
mailMessage.Subject = "Hello";//主题
mailMessage.Body = body;//内容
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
mailMessage.IsBodyHtml = true;//设置为HTML格式
mailMessage.Priority = MailPriority.High;//优先级
try
{
smtpClient.Send(mailMessage);
label11.Text = "ok";
//return true;
}
catch
{
label11.Text = "false";
//return false;
}
} --------------------编程问答--------------------
using System.Web;
using System.Web.Mail;
邮件msdn已经非常详细,拷过来就能用啦
System.Web.Mail.MailMessage mail=new MailMessage();
mail.From="..";
mail.To="..";
mail.Subject="hi";
mail.BodyFormat = MailFormat.Html;
System.Web.Mail.SmtpMail.SmtpServer="192.168...";
System.Web.Mail.SmtpMail.Send(mail);
我的是2003
补充:.NET技术 , C#