我试图使用MailMessage class构建传送到SMTP服务器以使用SmtpClient类进行传送的电子邮件。 我的电子邮件是通过交换服务器在outlook上配置的。 关于上述实现,我有以下怀疑:将MailMessage发送到Exchange服务器并发送到SMTP服务器之间的区别
1)Exchange Server和SMTP服务器有什么区别?
2)在我的情况下,我的outlook是使用我的证书在交换服务器上配置的。如何找到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(
"[email protected]",
"[email protected]",
"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();
}
@Phoenix:contoso.com是一个示例域。这些电子邮件不是真实的。没有必要把它们弄糟。 – BoltClock 2011-06-14 18:28:58