Why messages sent by smtpclient do not appear in sent items

I have implemented a server that sends emails via .Net SmtpClient. the mail sending code is as follows:

private static MailMessage SendMail(string to, string subject, string body) { MailMessage mailToSend = new MailMessage(); mailToSend.Body = body; mailToSend.Subject = subject; mailToSend.IsBodyHtml = true; mailToSend.To.Add(to); try { mailClient.Send(mailToSend); } catch (Exception ex) { //Log data... } mailToSend.Dispose(); } 

and in Web.config I set the mail credentials, something like this:

 <configuration> <system.net> <mailSettings> <smtp from=" autoemail@mailserver.org "> <network host="smtp.mailserver.org" password="pswdpswd" port="25" userName="autoemail" clientDomain="the-domain" enableSsl="true" /> </smtp> </mailSettings> </system.net> </configuration> 

The letters were sent successfully, and everything works fine, but when I log in to the email user on the exchange server (for example, through the Outlook Web-App), I don’t see the mail sent through SmtpClient (via code) in the folder of the sent goods.

How can I save a copy of sent emails in these folders? Thanks!

+7
c # email smtpclient exchange-server
source share
1 answer

They are not recorded in the sent items, since they are sent only with a user account at the SMTP level, in fact, he does not use a mailbox to send email.

The only thing you have is not to use SmtpClient and use the Exchange API to send mail.

From the above example:

 ExchangeService service = new ExchangeService(); service.AutodiscoverUrl(" youremailaddress@yourdomain.com "); EmailMessage message = new EmailMessage(service); message.Subject = subjectTextbox.Text; message.Body = bodyTextbox.Text; message.ToRecipients.Add(recipientTextbox.Text); message.Save(); message.SendAndSaveCopy(); 
+13
source share

All Articles