通过asp.net网站发送电子邮件 [英] send email with asp.net website

查看:79
本文介绍了通过asp.net网站发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的asp.net网站上发送电子邮件,这是我的代码,但是我有错误,有人可以找出我的错误在哪里吗????

 受保护的  void  btnsend_Click(对象发​​件人,EventArgs e)
{
尝试
{
字符串 bodyHTML = 字符串 .Empty;
字符串 bodyPlain = 字符串 .Empty;
MailMessage mailMsg =  MailMessage(" ,txtemail.Text);
mailMsg.Subject = txtsubject.Text;
mailMsg.IsBodyHtml =  true ;
bodyHTML = txtbody.text;

AlternateView htmlView = AlternateView.CreateAlternateViewFromString(bodyHTML," );
AlternateView plainView = AlternateView.CreateAlternateViewFromString(bodyPlain," );

mailMsg.AlternateViews.Add(htmlView);
mailMsg.AlternateViews.Add(plainView);
SmtpClient smtp =  SmtpClient();
smtp.Port =  25 ;
smtp.Host = " ;

smtp.Send(mailMsg);
lblsend.Text = " ;
}

捕获(例外)
{
lblsend.Text = ex.ToString();
}

} 

解决方案

smtp.website.com是否存在,或者您是否将此文件复制到网上?您需要更改此代码以指向实际的邮件服务器.如果您想让我们为您解码它,您还应该告诉我们实际的错误消息.


您得到的实际错误是什么?
检查您的smtp服务器是否支持SSL和身份验证,

if (_ssl == "SSL")
{
    smtpClient.EnableSsl = true;
}
else
{
    smtpClient.EnableSsl = false;
}
if (_isauthenticate == "Yes")
{
    smtpClient.UseDefaultCredentials = false;
    credentials =
            new System.Net.NetworkCredential(str_user, str_password);

    smtpClient.Credentials = credentials;
}
else
{
    smtpClient.UseDefaultCredentials = true;
    credentials =
            new System.Net.NetworkCredential();
    smtpClient.Credentials = credentials;

}



希望这会有所帮助.
欢呼


我尝试使用来自此的gmail(protected void btnsend_Click(object sender, EventArgs e) { try { string bodyHTML = string.Empty; string bodyPlain = string.Empty; MailMessage mailMsg = new MailMessage("info@website.com", txtemail.Text); mailMsg.Subject = txtsubject.Text; mailMsg.IsBodyHtml = true; bodyHTML = txtbody.text; AlternateView htmlView = AlternateView.CreateAlternateViewFromString(bodyHTML, null, "text/html"); AlternateView plainView = AlternateView.CreateAlternateViewFromString(bodyPlain, null, "text/plain"); mailMsg.AlternateViews.Add(htmlView); mailMsg.AlternateViews.Add(plainView); SmtpClient smtp = new SmtpClient(); smtp.Port = 25; smtp.Host = "smtp.website.com"; smtp.Send(mailMsg); lblsend.Text = "email sent"; } catch(Exception ex) { lblsend.Text = ex.ToString(); } }

解决方案

Does smtp.website.com exist, or did you copy this off the web ? You need to change this code to point to an actual mail server. You also should tell us the actual error message, if you want us to decode it for you.


What is the actual error you are getting?
Check whether your smtp server supports SSL and Authentication,

if (_ssl == "SSL")
{
    smtpClient.EnableSsl = true;
}
else
{
    smtpClient.EnableSsl = false;
}
if (_isauthenticate == "Yes")
{
    smtpClient.UseDefaultCredentials = false;
    credentials =
            new System.Net.NetworkCredential(str_user, str_password);

    smtpClient.Credentials = credentials;
}
else
{
    smtpClient.UseDefaultCredentials = true;
    credentials =
            new System.Net.NetworkCredential();
    smtpClient.Credentials = credentials;

}



Hope this helps.
cheers


i try using gmail from this (Send E-Mail from your .NET Application using your GMail Account[^]) and it worked fine.


这篇关于通过asp.net网站发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆