Posts o[csharp] Send mail with Exchange Server
Post
Cancel

o[csharp] Send mail with Exchange Server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
string sSMTPHost = "relay.x.p1piscrew.com"; // exchange SMTP

StringBuilder sBody = new StringBuilder();
sBody.Append("Hi PipisCrew,  
 This is a test");

MailAddress from = new MailAddress("robot@p1piscrew.com");

MailMessage message = new MailMessage();

// Create  the file attachment for this e-mail message.
string csvFileFullPath = "W:\test.txt";
Attachment data = new Attachment(csvFileFullPath, MediaTypeNames.Application.Octet);
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(csvFileFullPath);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(csvFileFullPath);
disposition.ReadDate = System.IO.File.GetLastAccessTime(csvFileFullPath);

// Add the file attachment to this e-mail message.
message.Attachments.Add(data);

message.IsBodyHtml = true;
message.SubjectEncoding = Encoding.UTF8;
message.Subject = "test mail for exchange";
message.Body = sBody.ToString();
message.From = from;
message.To.Add("x@pip1screw.com");

SmtpClient smtpClient = new SmtpClient(sSMTPHost);

smtpClient.Send(message);

using authentication follow : http://stackoverflow.com/a/18009190

find smtp http://stackoverflow.com/a/1461224

origin - http://www.pipiscrew.com/?p=6136 csharp-send-mail-with-exchange-server

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags