I have implemented a server that sends emails via .Net SmtpClient. the mail sending code looks like that:
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've put the mail's credentials, someting like that:
<configuration>
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.mailserver.org" password="pswdpswd" port="25" userName="autoemail" clientDomain="the-domain" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
</configuration>
The emails sent successfuly and everything works fine BUT when I'm logging in to the email user in the exchange server (in example via Outlook Web-App) I can't see the mail sent via SmtpClient (via code) in the sent items folder.
how can I keep a copy of the sent mails in this folders? Thanks!
I can't find an item in my Sent Items folder There are several reasons why an item might not appear in your Sent Items folder. The item hasn't been sent yet. If the email message isn't sent successfully, for example because of connectivity problems or logon issues, it might be stuck in your Outbox folder.
SMTP mail is never copied to a Sent folder automatically. The Sent folder is an IMAP folder and has nothing to do with SMTP. The mail client might save a copy using IMAP, but never the SMTP server.
This class allows you to attach files, streams, or text to an email message. MailAddress. Represents the email address of the sender and recipients. MailMessage.
With e-mail, Sent or Sent items is a folder or area that stores any e-mails that were successfully delivered. The sent items is different than the outbox, which is a location where e-mail stays until it is delivered.
They are not recorded in the sent items since it is only send using the account from the user on SMTP level, it doesn't really use the mailbox to send the email.
The only option you have is not to use SmtpClient
and use the Exchange API to send mail.
From their sample referenced:
ExchangeService service = new ExchangeService();
service.AutodiscoverUrl("[email protected]");
EmailMessage message = new EmailMessage(service);
message.Subject = subjectTextbox.Text;
message.Body = bodyTextbox.Text;
message.ToRecipients.Add(recipientTextbox.Text);
message.Save();
message.SendAndSaveCopy();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With