通过asp.net发送电子邮件 [英] sending email throug asp.net

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

问题描述

这是我的设计页面

This is my Design page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="register" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table style="border:1px solid" align="center">
    <tr><td>Username:</td><td><asp:TextBox runat="server" ID="txtUsername"></td></tr>
    <tr><td>Password:</td><td><asp:TextBox runat="server" ID="txtPassword" TextMode="Password"></td></tr>
    <tr><td valign="top">Address:</td><td><asp:TextBox runat="server" ID="txtAdress" TextMode="MultiLine"></td></tr>
    <tr><td>Email-id:</td><td><asp:TextBox runat="server" ID="txtEmail"></td></tr>
    <tr><td colspan="2" align="center"><asp:Button runat="server" ID="btnRegister" 

            Text="Register" onclick="btnRegister_Click" /></td></tr>
    </table>
    
    </div>
    </form>
</body>
</html>





这是我的代码页



this is my code page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

public partial class register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        MailMessage msg = new MailMessage();
        msg.To.Add(txtEmail.Text);
        msg.From = new MailAddress("mysiteadmin@peers");
        msg.Subject="thanks for registraion";
        msg.Body="thanks for registraion";
        SmtpClient obj = new SmtpClient();
        obj.Host = "sri";obj.Send(msg);
        Response.Write("<h2>Registered</h2>");

    }
}







这里收到错误以下....请你帮忙




Here am getting an error below.... can u please help

Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 100.64.243.189 (100.64.243.189:25), connect error 10061

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.Net.Mail.SmtpException: Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 100.64.243.189 (100.64.243.189:25), connect error 10061

Source Error: 
Line 21:         msg.Body="thanks for registraion";
Line 22:         SmtpClient obj = new SmtpClient();
Line 23:         obj.Host = "sri";obj.Send(msg);
Line 24:         Response.Write("<h2>Registered</h2>");
Line 25:

推荐答案

这里有一些问题您的smtp详细信息请使用以下链接:



ASP.Net:发送电子邮件 [ ^ ]



希望它能解决你的问题。



谢谢。
here is some problem with your smtp details please go with the below link :

ASP.Net: Send emails[^]

hope it ll solve your problem.

Thanks.


可能有两个原因:

1.这通常是因为尝试连接到不活动的服务外国主持人。 2.有时10061错误是由本地计算机或网络连接上的防火墙或防病毒软件引起的。



任何一个都可能阻塞所需的端口成功连接到服务器。你去了错误的主机,或者你试图联系的服务器应用程序没有执行。检查您使用的目标地址。检查,如果你使用了主机名,它是否解析为正确的地址..



--Amit
There may be two cause:
1. This usually results from trying to connect to a service that is inactive on the foreign host. 2. Sometimes a 10061 error is caused by either a firewall or anti-virus software presence on the local computer or network connection.

Either one may be blocking the ports needed to make a successful connection to the server. Either you went to the wrong host, or the server application you''re trying to contact is not executing. Check the destination address you are using. Check, if you used a hostname, did it resolve to the correct address or not..

--Amit


根据我的端口是问题,

所以请检查以下方法。



According to me port is the problem,
So Please Check below method.

var fromAddress = "Gmail@gmail.com";
  // any address where the email will be sending
  var toAddress = YourEmail.Text.ToString();
  //Password of your gmail address
  const string fromPassword = "Password";
   // Passing the values and make a email formate to display
  string subject = YourSubject.Text.ToString();
  string body = "From: " + YourName.Text + "\n";
  body += "Email: " + YourEmail.Text + "\n";
  body += "Subject: " + YourSubject.Text + "\n";
  body += "Question: \n" + Comments.Text + "\n";
  // smtp settings
  var smtp = new System.Net.Mail.SmtpClient();
  {
      smtp.Host = "smtp.gmail.com";
      smtp.Port = 587;
      smtp.EnableSsl = true;
      smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
      smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
      smtp.Timeout = 20000;
  }
  // Passing values to smtp object
  smtp.Send(fromAddress, toAddress, subject, body);


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

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