如何使用SMTP通过Exchange Server发送邮件 [英] How Can i Send Mail Through Exchange Server by using SMTP

查看:1238
本文介绍了如何使用SMTP通过Exchange Server发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在没有

NetworkCredential nc = new Net.NetworkCredential("USERNAME", "PASSWORD"). 

仅使用Exchange主机(服务器名称)和端口

BY using Only Exchange Host (Server Name) And Port

我正在获取错误对于此代码:邮箱不可用.服务器响应为:5.7.1客户端无权以该发送者的身份发送

Im Getting Error For this code : Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender

protected void SendEmail(object sender, EventArgs e)
{
    SmtpClient smtpClient = new SmtpClient("ExchangeServerName",25);
    MailMessage message = new MailMessage();
    try
    {
        MailAddress fromAddress = new MailAddress("bala@OfficeName.com", "From Me");
        MailAddress toAddress = new MailAddress("bala@OfficeName.com", "To You");
        message.From = fromAddress;
        message.To.Add(toAddress);
        message.Subject = "Testing!";
        message.Body = "This is the body of a sample message";
        smtpClient.UseDefaultCredentials = true;
        System.Net.NetworkCredential nc = CredentialCache.DefaultNetworkCredentials;
        smtpClient.Credentials = (System.Net.ICredentialsByHost)nc.GetCredential("ExchangeServerName", 25, "Basic");
        smtpClient.Send(message);
        lblText.Text ="Email sent.";
    }
    catch (Exception ex)
    {
        lblText.Text = "Coudn't send the message!\n  " + ex.Message;
    }
}

推荐答案

我已经完成了.有关我的代码的更多详细信息,请使用

I have done it. For more details about my code use this link.

下面的代码可以正常工作

Below Code is worked Fine with

服务器:Windows Server 2003,Windows Server 2008,Windows Server 2008 R2

Server : Windows Server 2003,Windows Server 2008,Windows Server 2008 R2

IIS:6.0、7.0

IIS : 6.0, 7.0

.Net Frame Wotk:2.0、3.5、4.0

.Net Frame Wotk : 2.0,3.5,4.0

string sMessage;
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{

 //you can provide invalid from address. but to address Should be valil
MailAddress fromAddress = new MailAddress("bala@technospine.com", "BALA");

smtpClient.Host = "Exchange Server Name";
smtpClient.Port = 25;
//smtpClient.Port = 587;


smtpClient.UseDefaultCredentials = true; 

message.From = fromAddress;
message.To.Add(bala@technospine.com); //Recipent email 
message.Subject = _subject;
message.Body = _details;
message.IsBodyHtml = true;

//smtpClient.EnableSsl = true; 

smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

smtpClient.Send(message); 

sMessage = "Email sent.";
}
catch (Exception ex)
{
sMessage = "Coudn't send the message!\n " + ex.Message;
}


lblMailStatus.Text = sMessage;

这篇关于如何使用SMTP通过Exchange Server发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆