在asp.net 2.0中发送电子邮件 [英] Send Email in asp.net 2.0

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

问题描述

尊敬的先生/女士,

早上好,

我正在.NET 2.0中开发一个asp.net Web应用程序.
我想在我的应用程序中发送电子邮件.我正在使用此代码发送电子邮件.

代码:

Dear Sir/Madam,

Very Good Morning,

I am develop an asp.net web application in .NET 2.0.
I want to send e-mail in my application.I am Use this Code for send Email.

code:

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.Web.Mail;
public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label5.Visible= false;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label5.Visible= true;
        MailMessage msg = new MailMessage();

        msg.To = TextBox1.Text;
        msg.From = TextBox2.Text;
        msg.Subject = TextBox3.Text;
        msg.Body = TextBox4.Text;
        Label5.Text = "Sending...";
        SmtpMail.SmtpServer ="smtp.realpowermoney.com";

        SmtpMail.Send(msg);
        Label5.Text = "Message sent";
    }
}
Error:
<pre lang="msil">The transport failed to connect to the server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: The transport failed to connect to the server.

Source Error:

Line 35:
Line 36:
Line 37:         SmtpMail.Send(msg);
Line 38:
Line 39:         Label5.Text = "Message sent";

Source File: e:\HostingSpaces\say2me\realpowermoney.com\wwwroot\Default.aspx.cs    Line: 37



Sir/Madam,
   How to solve the Error.Plz help Me.

With Regards,
Debapriya

推荐答案

听起来像您还没有准备好使用此Web服务器.它真的不需要用户名或密码吗?
Sounds like you haven''t set yourself up to use this web server. Does it really not need a username or password ?


u可以使用它.通过使用以下代码,我发送了邮件.
在这种情况下,我使用了Gmail帐户.

u can use this. by using the following code i sent mail.
In this case i used Gmail account.

MailMessage mail = new MailMessage();
mail.From = new MailAddress(textBoxFrom.Text);
mail.To.Add(textBoxTo.Text);
mail.Subject = textBoxSubj.Text;
mail.Body = textBoxBody.Text;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

smtp.EnableSsl = true;
smtp.Credentials = new  NetworkCredential("Your-Gmail-account", "gmail-password");
//Your-Gmail-account="aaa@gmail.com" ,
//gmail-password="123456"

try
{
    smtp.Send(mail);
    lblStatusMsg.Text = "Message sent";
}
catch (SmtpException ex)
{
    MessageBox.Show(ex.Message, "Error: " + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
}


好像您没有为电子邮件配置Web.Config文件,例如:
Looks like you have not configured the Web.Config file for Emails, like:
<configuration>
  <!-- Add the email settings to the <system.net> element -->
  <system.net>
    <mailSettings>
      <smtp>
        <network 

             host="relayServerHostname" 

             port="portNumber"

             userName="username"

             password="password" />
      </smtp>
    </mailSettings>
  </system.net>

  <system.web>
    ...
  </system.web>
</configuration>



请查看这篇文章以了解详细信息:
在ASP.NET 2.0中发送电子邮件 [



Have a look at this article for details:
Sending Email in ASP.NET 2.0[^]


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

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