发送e-mail失败??急救!!!!

jiangtianyin 2009-04-07 07:42:22
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
public partial class E_mail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.senter.Text = "mingsheng@yeah.com";
string Email = Request.QueryString["Email"];
this.geter.Text = Email;
}

protected void SendButton_Click(object sender, EventArgs e)
{
string from = "jiangtianyin@126.com";
string to = "mingshenghelp@163.com";
string subject = "kjfdsjfk";
string body = "jkdjfkjfsfkdjfsjkdj";
string username = "jiangtianyin@126.com";
string password = "我的邮箱密码,保密";
string smthost = "smtp.163.net";
Send(to, from, subject, body, username, password, smthost);
}
public void Send(string to, string from, string subject, string body, string userName, string password, string smtpHost)
{
MailAddress Mailfrom = new MailAddress(from);
MailAddress Mailto = new MailAddress(to);
MailMessage message = new MailMessage(Mailfrom, Mailto);
message.Subject = subject;//设置邮件主题
message.IsBodyHtml = true;//设置邮件正文为html格式
message.Body = body;//设置邮件内容
SmtpClient client = new SmtpClient(smtpHost);
client.Credentials = new NetworkCredential(userName, password);
client.Send(message);
}

}
...全文
477 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
toxxj 2009-04-07
  • 打赏
  • 举报
回复
把你的用户名:string username = "jiangtianyin@126.com";
改成:string username = "jiangtianyin";
试下
toxxj 2009-04-07
  • 打赏
  • 举报
回复
以下代码能发送成功,你对比下与你的代码看有什么不同的地方吧
------------------------------------------------
using System.Net.Mail;

static string strHost = string.Empty;
static string strAccount = string.Empty;
static string strPwd = string.Empty;
static string strFrom = string.Empty;

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
strHost = "smtp.163.com"; //STMP服务器地址
strAccount = "你的登录用户名"; //SMTP服务帐号
strPwd = "你的登录密码"; //SMTP服务密码
strFrom = "test@163.com"; //发送方邮件地址

Response.Write(sendMail("test2@126.com", "这是一封测试邮件", "这是一封测试邮件的正文内容") ? "Success" : "Unsuccess");

// Console.ReadLine();
}



protected bool sendMail(string to, string title, string content)
{
SmtpClient _smtpClient = new SmtpClient();
_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
_smtpClient.Host = strHost; ;//指定SMTP服务器
_smtpClient.Credentials = new System.Net.NetworkCredential(strAccount, strPwd);//用户名和密码

MailMessage _mailMessage = new MailMessage(strFrom, to);
_mailMessage.Subject = title;//主题
_mailMessage.Body = content;//内容
_mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
_mailMessage.IsBodyHtml = true;//设置为HTML格式
_mailMessage.Priority = MailPriority.High;//优先级

//发送附件
if (FileUpload1.HasFile)
{
Attachment atfiles = new Attachment(FileUpload1.PostedFile.FileName);
_mailMessage.Attachments.Add(atfiles);
}

try
{
_smtpClient.Send(_mailMessage);
return true;
}
catch
{
return false;
}
}

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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