reg*_*gie 5 c# exchange-server smtpclient exchangewebservices
我正在尝试使用MailMessage类来构建传输到SMTP服务器以使用SmtpClient类传递的电子邮件.我的电子邮件是通过Exchange服务器在outlook上配置的.关于上述实施,我有以下疑问:
1)Exchange Server和SMTP服务器之间有什么区别?
2)在我的情况下,我的Outlook使用我的凭据在Exchange服务器上配置.如何找到SMTP地址,以便我能够实现MailMessage类?
3)如果上述实施技术不可行,是否有基于交换服务器通过应用程序发送电子邮件的想法?
我正在使用Visual Studio 2008,框架3.5 SP1,使用C#作为语言处理winforms应用程序.请帮我澄清疑惑.
编辑
我使用以下代码.它不会抛出任何错误,也不会产生任何错误.我试图发送电子邮件给自己,但无济于事
public static void CreateMessageWithAttachment(string server)
{
// Specify the file to be attached and sent.
// This example assumes that a file named Data.xls exists in the
// current working directory.
string file = "data.xls";
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
"ben@contoso.com",
"ben@contoso.com",
"Quarterly data report.",
"See the attached spreadsheet.");
// Create the file attachment for this e-mail message.
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
// Add the file attachment to this e-mail message.
message.Attachments.Add(data);
//Send the message.
SmtpClient client = new SmtpClient(server);
// Add credentials if the SMTP server requires them.
client.Credentials = CredentialCache.DefaultNetworkCredentials;
try {
client.Send(message);
}
catch (Exception ex) {
Console.WriteLine("Exception caught in CreateMessageWithAttachment(): {0}",
ex.ToString() );
}
data.Dispose();
}
Run Code Online (Sandbox Code Playgroud)
1)Exchange Server和SMTP服务器之间有什么区别?
Exchange服务器包含更多内容.
2)在我的情况下,我的Outlook使用我的凭据在Exchange服务器上配置.如何找到SMTP地址,以便我能够实现MailMessage类?
Outlook - >工具 - >帐户 - >编辑帐户.
它与Exchange服务器的地址相同.端口25是标准SMTP端口.Exchange可能需要身份验证.
3)如果上述实施技术不可行,是否有基于交换服务器通过应用程序发送电子邮件的想法?
你不能只是使用MailMessage,你也需要SmtpClient.
使用Exchange的示例:将已发送的MailMessage发送到"已发送文件夹"
| 归档时间: |
|
| 查看次数: |
8014 次 |
| 最近记录: |