本地计算机上的SMTP服务器设置,以使用C#在ASP.Net中使用自动电子邮件服务 [英] SMTP server settings on local machine to use automatic email service in ASP.Net using C#

查看:154
本文介绍了本地计算机上的SMTP服务器设置,以使用C#在ASP.Net中使用自动电子邮件服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一种功能,可以从本地计算机上的网站向任何gmail/yahoo/rediffmail/.........帐户发送自动电子邮件.请帮助我进行编码以及服务器设置(如果有).
添加了

I want a functionality to send automatic email to any gmail/yahoo/rediffmail/......... account from my website which is on my local machine. Please help me with the coding as well as server settings if any.
Have added

using System.Web.Mail;



我添加了一个单击按钮,将发生以下情况....



I have added a button on whose click, the following will happen....

try
       {
           SmtpMail.SmtpServer = "localhost";
           SmtpMail.Send("abcdef@rediffmail.com", "uvwxyz@gmail.com", "Hi", "Mail sent");
           Label9.Text = "Message sent!";
       }
       catch (Exception ex)
       {
           Label9.Text = ex.Message;
       }



单击按钮时,Label9.Text为:传输无法连接到服务器."
我是一个初学者,对这类事情不太了解???请完成项目.........:confused :: confused :: confused:



On button click, Label9.Text is: "The transport failed to connect to the server."
I am a beginner and dont know much about such things??? Plzzzzzzzzz reply....... Have to complete project......... :confused::confused::confused:

推荐答案

可以是由于各种原因.您需要一一看待它们.
港口开放吗?防火墙权限到位了吗?
进一步确保已在Web.Config中配置SMTP配置:
It can be because of various reasons. You need to look at them one by one.
Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>



如果需要,请查看此Microsoft Video教程:
使用ASP.NET发送来自网站的电子邮件 [



If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]
Further, if needed, there are lots of article on this very site on how to send emails.


在web.config中
in the web.config
<appSettings>
<add key="SMTP" value="hostname.com"/>
<add key="FROMEMAIL" value="myemailadderss@yahoo.com"/>
<add key="FROMEPWD" value="ur email pwd">
<add key="PORT" value="25">
</appSettings>


并使用以下代码发送邮件


and use following code to send the mail

protected bool Send(string To, string From, string Subj, string Msg)
    {
        try
        {
            string mFrom = From.ToString().Trim();
            string mTo = To.ToString().Trim();
            string mSubject = Subj.ToString().Trim();
            string mMsg = Msg.ToString().Trim();

            string mMailServer = ConfigurationManager.AppSettings.Get("SMTP");
            int mPort = Convert.ToInt32(ConfigurationManager.AppSettings.Get("PORT"));

            MailMessage message = new MailMessage(mFrom, mTo, mSubject, mMsg);
            SmtpClient mySmtpClient = new SmtpClient(mMailServer, mPort);
            // mySmtpClient.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["FROMEMAIL"], ConfigurationManager.AppSettings["FROMPWD"]);
            //mySmtpClient.EnableSsl = true;
            message.Priority = MailPriority.High;
            mySmtpClient.UseDefaultCredentials = true;
            mySmtpClient.Send(message);
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }


这篇关于本地计算机上的SMTP服务器设置,以使用C#在ASP.Net中使用自动电子邮件服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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