C#发送邮件收不到

xiongxyt1 2010-06-08 05:42:48
在http://win.51aspx.com/CV/GroupSendMail/
下在了一个,运行收不到邮件
我自己参照csdn写了一个最简单的
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;

namespace 发送邮件
{
class Program
{
static void Main(string[] args)
{
string to = "297861197@qq.com";
string from = "xiongxyt2@163.com";
//string to = "jane@contoso.com";
//string from = "ben@contoso.com";
string subject = "Using the new SMTP client.";
string body = @"Using this new feature, you can send an e-mail message from an application very easily.";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("smtp.163.com");
Console.WriteLine("Changing time out from {0} to 100.", client.Timeout);
client.Timeout = 100;
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
//client.Credentials = CredentialCache.DefaultNetworkCredentials;
try
{
client.Send(message);
}
catch (SmtpException se)
{
Console.WriteLine(se.Message);
}
}
}
}
输出超时,应该怎么办?
大家有C#编写的邮件既可以发送也可以收到的程序共享一下 啊。
...全文
1154 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
WhyBeMore 2011-05-31
  • 打赏
  • 举报
回复
学习了,支持一下!!!
xiaotimtim 2011-05-17
  • 打赏
  • 举报
回复
得教了
xiongxyt1 2010-06-08
  • 打赏
  • 举报
回复
非常感谢啊,现在163是默认开启smtp/pop3的,不过你不说我不知道,用七楼的方法实现了。
马老虎 2010-06-08
  • 打赏
  • 举报
回复
建议使用 163邮箱试一试!


using System.Net.Mail;


public static bool SendMail(string messTo,string messBody)
{
MailMessage mess = new MailMessage();
mess.From = new MailAddress("mmm306306@163.com", "报警系统");//发件人
mess.Subject = "报警系统";//主题
mess.IsBodyHtml = true;//允许HTML
mess.BodyEncoding = System.Text.Encoding.UTF8;//编码
mess.Body = messBody;
SmtpClient client = new SmtpClient();//new 出 客服端的 smtp
client.Host = "smtp.163.com";
client.Credentials = new System.Net.NetworkCredential("mmm306306", "xxxxxxxxx");//需要发件人的账号 密码
mess.To.Add(new MailAddress(messTo));//收件人 数组(可以群发)
try
{
client.Send(mess);
return true;
}
catch (Exception ex)
{
return false;
}
}

_________________________________________________________________________________________



MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "abc@126.com";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "abc"); //set your username here

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "your password"); //set your password

here SmtpMail.SmtpServer = "smtp.126.com"; //your real server goes here
SmtpMail.Send( mail );




wuyq11 2010-06-08
  • 打赏
  • 举报
回复
使用其他邮箱看看
public void MailSend(string MailFrom,string MailTo,string MailPwd,string Mailtitle,string MailCon)
{
MailMessage MyMail = new MailMessage();
MyMail.From = new MailAddress("", "");
MyMail.To.Add(new MailAddress(""));
MyMail.Subject = Mailtitle;
MyMail.Body = MailCon;
MyMail.IsBodyHtml = false;
SmtpClient smtpclient = new SmtpClient();
smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpclient.Host = "";
smtpclient.Credentials = new System.Net.NetworkCredential(MailFrom, MailPwd);
smtpclient.Send(MyMail);
}


jmail.Message Jmail = new jmail.Message();
DateTime t = DateTime.Now;
String Subject = "";
String body = "";
String FromEmail = "";
String ToEmail = "";
Jmail.Charset = "GB2312";
Jmail.ContentType = "text/html";
Jmail.AddRecipient(ToEmail, "", "");
Jmail.From = FromEmail;
Jmail.MailServerUserName = "";
Jmail.MailServerPassWord = "";
Jmail.Subject = Subject;
Jmail.ContentType="text/html";
Jmail.Body = body + t.ToString();
Jmail.Send("", false);
Jmail.Close();


捷哥1999 2010-06-08
  • 打赏
  • 举报
回复
睡神在睡觉 2010-06-08
  • 打赏
  • 举报
回复
而且,你163的邮箱把smtp/pop3开启了么?好像新申请的邮箱都不给开了,老用户能开
睡神在睡觉 2010-06-08
  • 打赏
  • 举报
回复
好像给qq邮箱发有特殊限制吧。。。试试别的邮箱,应该就没问题的,只要smtp没写错
deknight 2010-06-08
  • 打赏
  • 举报
回复

public class MailHelper
{
/// <summary>
/// 发邮件
/// </summary>
/// <param name="to">收件人(以分号分隔的电子邮件地址列表)</param>
/// <param name="subject">主题</param>
/// <param name="message">邮件体</param>
/// <param name="ishtml">是否使用HTML发出</param>
/// <example>SendMail("xxx@xxx.com", DateTime.Now.ToString(), DateTime.Now.ToString());</example>
public static void SendMail(string to, string subject, string message, bool ishtml, Encoding encode)
{
if (ishtml == false)
{
//message = CharHelper.Html2Text(message);
}
SmtpClient smtpClient = new SmtpClient();

System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("/");

MailSettingsSectionGroup netSmtpMailSection = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");

using (MailMessage msg = new MailMessage(netSmtpMailSection.Smtp.From, to, subject, message))
{
msg.BodyEncoding = encode;
msg.IsBodyHtml = ishtml;
smtpClient.Send(msg);
}
}

110,579

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧