2011-05-10 45 views
0

我是一个网站编程。我想在配置文件中发送一条消息给用户..现在在asp.net ..我把这个:我如何获得我的smtp主机?

<mailSettings> 

    <smtp from="[email protected]"> 

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

    </smtp> 

</mailSettings> 

我不知道它是如何在网络主机行为和什么呢..我想要将其更改为保存我的雅虎帐户的服务器。我明白,smtp是一些电子邮件服务器,发送电子邮件了..但我如何把它获得?它看起来怎样,?它是一个int,它是一个字符串吗?!?

MailMessage message = new MailMessage(); 

    message.From = new MailAddress("[email protected]"); 



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




    message.CC.Add(new MailAddress("[email protected]")); 

    message.Subject = "This is my subject"; 

    message.Body = "This is the content"; 



    SmtpClient client = new SmtpClient(); 

    client.Send(message); 

配置文件:

<mailSettings> 

    <smtp from="[email protected]"> 

    <network host="smtp.yahoo.com" port="25" userName="username" password="secret" defaultCredentials="true" />// where do i get the host?!? the host prevents me from sending an email 

    </smtp> 

</mailSettings> 
+0

这取决于你想使用什么smtp服务器......如果它是你想使用的ISP的smtp服务器,你可以问你的isp(或搜索他们的网站)。雅虎或任何其他邮件服务也是如此。你必须从他们(即他们的支持网站)获得正确的smtp服务器。 – fretje 2011-05-10 09:50:07

+0

另外:这是堆栈溢出的主题。超级用户或WebApps可能会更好。 – fretje 2011-05-10 09:51:05

回答

2

看看雅虎邮件帮助页面设置他们的SMTP服务器。它看起来像你需要成为一个雅虎! Mail Plus帐户持有人可以访问POP和SMTP服务器。也许你可以使用另一个邮件帐户 - 你的虚拟主机提供商的SMTP服务器将是最好的使用。阅读您的虚拟主机的帮助页面。

-3
using System.Configuration; 
using System.Web.Configuration; 
using System.Net.Configuration; 

Configuration configurationFile = WebConfigurationManager.OpenWebConfiguration("PathToConfigFile"); 

替代

configurationFile = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath) 

MailSettingsSectionGroup mailSettings = configurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup; 
+0

你为什么给我提供代码?我已经有代码..我想知道如何获得stmp主机 – 2011-05-10 09:47:43

+0

如果(mailSettings!= null) { string host = mailSettings.Smtp.Network.Host; string password = mailSettings.Smtp.Network.Password; string username = mailSettings.Smtp.Network.UserName; } – Pankaj 2011-05-10 09:50:11

1

网络主机是将处理发送电子邮件的物理服务器(SMTP服务器)的地址。它可能采用IP地址或域名的形式(例如mail.mydomain.com)。如果你正在一家公司工作,他们应该提供给你,

相关问题