【问题标题】:Send email with SMTP使用 SMTP 发送电子邮件
【发布时间】:2010-07-17 12:50:04
【问题描述】:

我在 IIS 中管理 SMTP 服务器配置,以通过 asp 发送电子邮件作为中继部分我添加了我的 PC IP 传递>高级我在智能主机中添加了我的域名作为 mail.elarabygroup.com。

我添加了这段代码:

<script runat="server">
        protected void SendEmail(object sender, EventArgs e)
        {
            SmtpClient smtpClient = new SmtpClient();
            MailMessage message = new MailMessage();
            try
            {
                // Prepare two email addresses
                MailAddress fromAddress = new MailAddress(
                "karim-gamal@elarabygroup.com", "From Kareem Test");
                MailAddress toAddress = new MailAddress(
                "fady-eltegany@elarabygroup.com", "From Kareem Test");
                // Prepare the mail message

                message.From = fromAddress;
                message.To.Add(toAddress);
                message.Subject = "Testing!";
                message.Body = "This is the body of a sample message";
                // Set server details
                smtpClient.Host = "localhost";
                // Uncomment for SMTP servers that require authentication
                //smtpClient.Credentials = new System.Net.NetworkCredential(
                // "user", "password");
                // Send the email
                smtpClient.Send(message);
                // Inform the user
                statusLabel.Text = "Email sent.";
            }
            catch (Exception ex)
            {
                // Display error message
                statusLabel.Text = "Coudn't send the message!";
            }
        }
    </script>

但是出现错误:

邮箱不可用。服务器响应为:5.7.1 Unable to relay for fady-eltegany@larabygroup.com

【问题讨论】:

    标签: iis asp-classic smtp


    【解决方案1】:

    与电子邮件服务器的管理员交谈。默认情况下显然不允许您进行中继,因此您可能需要向服务器提供登录名/密码组合(请参阅您的 sn-p 中的NetworkCredentials)。

    您表示您的中继可能是mail.elarabygroup.com---那里的“e”是故意的;它与您在示例中使用的域不同?这可能是你不被允许转播的原因。

    【讨论】:

    • “e”我错过了,但不是原因。另外 karim-gamal@elarabygroup.com 我通过 Outlook 使用它来发送和接收电子邮件。
    • Don't tag not-programming-related. (另外,一个有 3 个字母的名字,所以 comment replies 工作,会很有帮助。:)
    猜你喜欢
    • 2016-04-17
    • 1970-01-01
    • 2011-07-30
    • 2015-11-10
    • 2023-03-09
    • 2013-08-16
    • 2017-01-26
    • 2013-09-22
    相关资源
    最近更新 更多