MailMessage class을 사용하여 SmtpClient 클래스를 사용하여 배달하기 위해 SMTP 서버에 전송되는 전자 메일 메시지를 구성하려고합니다. 전자 메일은 Exchange 서버를 통해 Outlook에 구성됩니다. 위의 구현과 관련하여 다음과 같은 의문점이있었습니다.MailMessage를 Exchange Server로 보내고 SMTP 서버로 보내는 것의 차이점
1) Exchange Server와 SMTP 서버의 차이점은 무엇입니까?
2) 내 경우 Outlook Express는 내 자격 증명을 사용하여 Exchange 서버에 구성됩니다. SMTP 메일 주소를 어떻게 찾을 수있어서 MailMessage 클래스를 구현할 수 있습니까?
3) 위의 구현 기술이 실행 가능하지 않은 경우 Exchange 서버를 기반으로하는 응용 프로그램을 통해 전자 메일을 보내는 아이디어가 있습니까?
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