【问题标题】:How to setup an SMTP server on Mac OS X?如何在 Mac OS X 上设置 SMTP 服务器?
【发布时间】:2012-06-25 20:14:46
【问题描述】:

我使用 PHP,我的机器上有 mamp。我想在我的 PHP 代码中发送电子邮件:

<?php
 $to = "recipient@example.com";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";
 if (mail($to, $subject, $body)) {
   echo("<p>Message successfully sent!</p>");
  } else {
   echo("<p>Message delivery failed...</p>");
  }
 ?>

如何在我的 mac 机器上免费配置邮件服务器?

【问题讨论】:

    标签: php macos email mamp osx-mountain-lion


    【解决方案1】:

    选项 1:

    CommandLineFu 有这个班轮在端口 25 上运行 SMTP 服务器:

    sudo python -m smtpd -n -c DebuggingServer localhost:25
    

    这将在您的本地机器上运行一个假的 smtp 服务器。它不会发送任何内容,但会将其转储到控制台。

    选项 2:

    如果您对命令行不满意,那么 FakeSMTP 是一个免费的 Fake SMTP 服务器,带有 GUI,用于轻松测试应用程序中的电子邮件。它是用 Java 编写的。它非常好用且易于使用。

    [http://nilhcem.com/FakeSMTP/][1]

    【讨论】:

    • 这太棒了
    【解决方案2】:

    以下人员完成了这项工作。见源here

    1. 编辑文件:sudo emacs /System/Library/LaunchDaemons/org.postfix.master.plist
    2. 在结束&lt;/dict&gt;标签之前添加&lt;key&gt;RunAtLoad&lt;/key&gt; &lt;true/&gt; &lt;key&gt;KeepAlive&lt;/key&gt; &lt;true/&gt;
    3. 运行sudo postfix start

    检查 SMPT 是否正在运行:telnet localhost 25

    【讨论】:

    • 虽然隔了很久,但请更新源码。它似乎不起作用。
    • 赛义德,缺失的文章不是我写的。随意寻找替代来源。
    • 我没有那个文件,虽然我有 /System/Library/LaunchDaemons/com.apple.postfix.master.plist 它没有编辑权限所以我试着启动服务,这似乎可以自己工作。
    【解决方案3】:

    Are there any smtp server i can install on linux mac ?

    Sending Mail from PHP Using SMTP Authentication - Example:

    <?php
     require_once "Mail.php";
    
     $from = "Sandra Sender <sender@example.com>";
     $to = "Ramona Recipient <recipient@example.com>";
     $subject = "Hi!";
     $body = "Hi,\n\nHow are you?";
    
     $host = "mail.example.com";
     $username = "smtp_username";
     $password = "smtp_password";
    
     $headers = array ('From' => $from,
       'To' => $to,
       'Subject' => $subject);
     $smtp = Mail::factory('smtp',
       array ('host' => $host,
         'auth' => true,
         'username' => $username,
         'password' => $password));
    
     $mail = $smtp->send($to, $headers, $body);
    
     if (PEAR::isError($mail)) {
       echo("<p>" . $mail->getMessage() . "</p>");
      } else {
       echo("<p>Message successfully sent!</p>");
      }
     ?>
    

    Sending Mail from PHP Using SMTP Authentication and SSL Encryption - Example:

    <?php
     require_once "Mail.php";
    
     $from = "Sandra Sender <sender@example.com>";
     $to = "Ramona Recipient <recipient@example.com>";
     $subject = "Hi!";
     $body = "Hi,\n\nHow are you?";
    
     $host = "ssl://mail.example.com";
     $port = "465";
     $username = "smtp_username";
     $password = "smtp_password";
    
     $headers = array ('From' => $from,
       'To' => $to,
       'Subject' => $subject);
     $smtp = Mail::factory('smtp',
       array ('host' => $host,
         'port' => $port,
         'auth' => true,
         'username' => $username,
         'password' => $password));
    
     $mail = $smtp->send($to, $headers, $body);
    
     if (PEAR::isError($mail)) {
       echo("<p>" . $mail->getMessage() . "</p>");
      } else {
       echo("<p>Message successfully sent!</p>");
      }
     ?>
    

    相关主题:

    【讨论】:

      【解决方案4】:

      试试这个 - http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm

      如果您希望 SMTP 服务器从 OSX 上发送邮件,这可能会有所帮助(实际上还没有尝试过,但似乎可以完成这项工作)-http://email.about.com/cs/sendmail/gr/sendmail_enable.htm

      希望有帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-12-20
        • 2011-04-20
        • 2015-03-04
        • 1970-01-01
        • 1970-01-01
        • 2013-07-27
        • 2017-06-08
        相关资源
        最近更新 更多