Я пытаюсь использовать класс MailMessage для создания сообщений электронной почты, которые передаются на SMTP-сервер для доставки с использованием класса SmtpClient.
Моя электронная почта настроена на outlook через сервер обмена.
У меня были следующие сомнения относительно вышеупомянутой реализации:
1) В чем разница между сервером Exchange и сервером SMTP?
2) В моем случае мой внешний вид настраивается на сервере Exchange с использованием моих учетных данных. Как мне найти SMTP-адрес, чтобы я мог реализовать класс MailMessage?
3) Есть ли какие-либо идеи по отправке электронных писем через приложение на основе сервера Exchange, если описанная выше методика реализации невозможна?
Я использую Visual Studio 2008, Framework 3.5 SP1, работаю над приложением winforms с C # в качестве языка. Пожалуйста, помогите мне прояснить мои сомнения.
EDIT
Я использую следующий код. Это не выдает никакой ошибки, и при этом это не работает. Я пытаюсь отправить и написать себе, но безрезультатно
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();
}