【问题标题】:Sending email with C# without SMTP Server? [duplicate]在没有 SMTP 服务器的情况下使用 C# 发送电子邮件? [复制]
【发布时间】:2014-01-13 15:30:42
【问题描述】:

我正在制作一个简单的网站。它托管在我运行 IIS 7 并具有完全访问权限的 VPS 上。 DNS 已设置和配置,但没有配置邮件服务器或任何东西。

我希望用户能够通过非常简单的表单发送反馈。

但是,我没有 SMTP 服务器(据我所知)。

string from = "";
    string to = "someemails@hotmail.com";
    string subject = "Hi!";
    string body = "How are you?";
    SmtpMail.SmtpServer = "mail.example.com";
    SmtpMail.Send(from, to, subject, body);

我想将邮件发送到一个免费的电子邮件帐户,但由于我没有 SMTP 服务器,我不确定如何发送。

我还有其他方法可以做到吗?或者一些替代品(比如使用免费的 smpt 或其他东西)

谢谢

【问题讨论】:

  • 您可以使用您的邮件提供商的 SMTP 服务器。 (smtp.gmail.com、smtp.live.com 或其他)
  • 不清楚您在寻找什么 - SMTP 服务器位置(在 SO 上与搜索外部工具无关,但一些由 Steve 提供)、间接发送邮件的方式(Outlook 互操作?)或方式配置你自己的 SMTP 服务器(更适合ServerFault.com
  • 您需要阅读更多关于 SMTP 客户端和服务器的角色。当你这样做时,你会意识到没有一个你就无法做你想做的事情。

标签: c# asp.net email


【解决方案1】:

没有 smtp 服务器就无法发送,但您可以使用您的 emailprovider 或免费的 smtp,如 turbosmtp http://www.serversmtp.com/en/free-smtp-server

【讨论】:

    【解决方案2】:

    不建议直接从您的代码向接收邮件服务器发送电子邮件,就接收邮件服务器而言,这就像运行您自己的邮件服务器一样。正确运行邮件服务器以确保可靠地传递电子邮件需要做很多事情。例如,其中一件事(非常重要)是拥有正确的reverse dns records(披露:我工作的公司的文档链接)。

    相反,您应该通过真实的电子邮件服务器中继您的电子邮件。您可以使用您已有的任何电子邮件地址的 SMTP 服务器,包括 gmail。

    @987654322@@987654323@@987654324@ 一起使用(如果支持)。

    代码示例:

    using System.Net;
    using System.Net.Mail;
    
    string fromEmail = "FromYou@gmail.com";
    MailMessage mailMessage = new MailMessage(fromEmail, "ToAnyone@example.com", "Subject", "Body");
    SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
    smtpClient.EnableSsl = true;
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = new NetworkCredential(fromEmail, "password");
    try {
        smtpClient.Send(mailMessage);
    }
    catch (Exception ex) {
        //Error
        //Console.WriteLine(ex.Message);
        Response.Write(ex.Message);
    }
    

    【讨论】:

    • 您可能应该在第一段中披露您与链接到的服务的从属关系。
    【解决方案3】:

    或者,在你的配置文件中,你可以把

    <configuration>
      <system.net>
         <mailSettings>
          <smtp deliveryMethod="SpecifiedPickupDirectory">
            <specifiedPickupDirectory pickupDirectoryLocation="C:\somedirectory" />
          </smtp>
         </mailSettings>
      </system.net>
    </configuration>
    

    这将导致所有发送的邮件都发送到指定PickupDirectory 中的磁盘,而不必配置 SMTP 设置。

    【讨论】:

      猜你喜欢
      • 2014-08-11
      • 1970-01-01
      • 2013-06-23
      • 2013-07-22
      • 1970-01-01
      • 2011-06-06
      • 2013-12-08
      • 1970-01-01
      • 2015-12-12
      相关资源
      最近更新 更多