使用SMTP发送电子邮件

时间:2010-07-17 12:50:04

标签: iis asp-classic smtp

我在IIS中管理SMTP服务器配置以通过asp作为中继部分发送电子邮件我添加了My PC IP Delivery> Advanced我在智能主机中添加了我的域名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无法转发fady-eltegany@larabygroup.com

1 个答案:

答案 0 :(得分:0)

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

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