本文介绍了从ASP.NET发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我尝试了许多排列和组合来从ASP发送邮件.

但是结果仍然是负面的.没有错误,但是收件箱中没有邮件.

代码如下.

Dear All,

I tried many permutations and combinations for sending a mail from ASP.

But the result is still negative. There is no error but there is no mail in the inbox.

code is as follows.

protected void Button1_Click(object sender, EventArgs e)
    {
        MailMessage message = new MailMessage();
        SmtpClient smtpClient = new SmtpClient();

        smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

        try
        {
            MailAddress fromAddress = new MailAddress(Textbox2.Text, TextBox1.Text);


            //Default port will be 25

            smtpClient.Port = 25;
            message.From = fromAddress;




            message.To.Add("[email protected]");

            message.IsBodyHtml = false;
            message.Body = TextBox3.Text;
            message.Subject = "test";

            smtpClient.Send(message);



            Label3.Text = "Email Sent";


        }
        catch(Exception ex)

        {
            Label3.Text = "Sending Failed" + ex.Message;


        }


    }




我在web.config中进行了以下更改.




I have made the following changes in web.config.

<system.net>
    <mailSettings>

        <network host="192.168.1.33" port="25" userName="username" password="password" defaultCredentials="true" />

    </mailSettings>



有人可以在这里让我知道主机或SMTP服务器的确切含义吗,它是"smtp.gmail.com","localhost"或我的IP地址".

我想我没有正确指定此参数,这就是我面临的问题.

我也想知道是否应提供该用户名和密码????

请协助.

提前致谢.
Mukund G Kallapur



Can anybody let me know th exact meaning of the host or the SMTP Server here, it is "smtp.gmail.com", or "localhost", or "my IP address".

I guess I am not specifying this parameter correctly, thats y i am facing the problem.

Also I wanted to know whether that user name and password should be provided or no ???

Kindly assist.

Many Thanks in Advance.
Mukund G Kallapur

推荐答案

<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="network">
        <network

          host="localhost"

          port="25"

          defaultCredentials="true"

        />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>


http://msdn.microsoft.com/en-us/library/w355a94k.asp [ ^ ]

如果您想通过Gmail实际发送电子邮件,那么我相信您可以将smpt.gmail.com指定为服务器(端口应保持25),但是您需要提供gmail用户名和密码,而不要使用DefaultCredentials


http://msdn.microsoft.com/en-us/library/w355a94k.asp[^]

If you want to actually send your email through Gmail then I believe you can specify smpt.gmail.com as the server (the port should stay on 25) but you''d then need to give your gmail username and password and not use DefaultCredentials


这篇关于从ASP.NET发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 07:19