我如何获得我的smtp主机?

时间:2011-05-10 09:41:29

标签: c# asp.net gmail

我为一个网站编程。我想向用户发送消息..现在在配置文件中的asp.net中..我把它:

<mailSettings>

  <smtp from="makovetskiyd@yahoo.co.uk">

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

  </smtp>

</mailSettings>

我不知道网络主机如何行动以及它做了什么..我想将其更改为持有我的雅虎帐户的服务器。据我所知,smtp是一些发送电子邮件的电子邮件服务器..但我如何获取它?它看起来怎样,?它是一个int,它是一个字符串吗?!?

 MailMessage message = new MailMessage();

    message.From = new MailAddress("makovetskiyd@yahoo.co.uk");



    message.To.Add(new MailAddress("makovetskiyd@yahoo.co.uk"));




    message.CC.Add(new MailAddress("makovetskiyd@yahoo.co.uk"));

    message.Subject = "This is my subject";

    message.Body = "This is the content";



    SmtpClient client = new SmtpClient();

    client.Send(message);

配置文件:

    <mailSettings>

  <smtp from="makovetskiyd@yahoo.co.uk">

    <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>

3 个答案:

答案 0 :(得分:2)

看看雅虎!邮件帮助页面,用于SMTP服务器的设置。看起来你需要成为雅虎!但是Mail Plus帐户持有者可以访问POP和SMTP服务器。也许您可以使用其他邮件帐户 - 您的网络托管服务提供商的SMTP服务器将是最好的使用。阅读您的网站托管服务商帮助页面。

答案 1 :(得分:1)

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

答案 2 :(得分:-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;