Iis 使用SMTP发送电子邮件
我在IIS中管理了SMTP服务器配置,以便通过asp作为中继发送电子邮件。我在智能主机中添加了我的PC IP Delivery>Advanced我将我的域名添加为mail.elarabigroup.com 我添加了以下代码:Iis 使用SMTP发送电子邮件,iis,asp-classic,smtp,Iis,Asp Classic,Smtp,我在IIS中管理了SMTP服务器配置,以便通过asp作为中继发送电子邮件。我在智能主机中添加了我的PC IP Delivery>Advanced我将我的域名添加为mail.elarabigroup.com 我添加了以下代码: <script runat="server"> protected void SendEmail(object sender, EventArgs e) { SmtpClient smtpClient =
<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>
受保护的void sendmail(对象发件人,事件参数e)
{
SmtpClient SmtpClient=新的SmtpClient();
MailMessage=新的MailMessage();
尝试
{
//准备两个电子邮件地址
MailAddress fromAddress=新邮件地址(
“卡里姆-gamal@elarabygroup.com“,”来自Kareem测试“);
MailAddress to Address=新邮件地址(
“法迪-eltegany@elarabygroup.com“,”来自Kareem测试“);
//准备邮件消息
message.From=fromAddress;
message.To.Add(toAddress);
message.Subject=“测试!”;
message.Body=“这是示例消息的正文”;
//设置服务器详细信息
smtpClient.Host=“localhost”;
//取消需要身份验证的SMTP服务器的注释
//smtpClient.Credentials=new System.Net.NetworkCredential(
//“用户”、“密码”);
//发送电子邮件
发送(消息);
//通知用户
statusLabel.Text=“电子邮件已发送。”;
}
捕获(例外情况除外)
{
//显示错误消息
statusLabel.Text=“无法发送邮件!”;
}
}
但出现了一个错误:
邮箱不可用。服务器响应为:5.7.1无法为fady中继-eltegany@larabygroup.com
与电子邮件服务器的管理员交谈。默认情况下,您显然不允许中继,因此您可能需要向服务器提供登录/密码组合(请参阅代码段中的
NetworkCredentials
)
您指出您的中继可能是mail.elarabigroup.com
——其中的“e”是故意的;它与您在示例中使用的域不同?这可能是你不能接力的原因。我错过了“e”,但不是原因。还有卡里姆-gamal@elarabygroup.com我通过outlook使用它发送和接收电子邮件。(另外,一个有3个字母的名字,所以工作会很有帮助。:)