'Get all emails in inbox .Net.Mail C#
I'm making a small program that can send emails and read emails. I can currently send emails however I'm not sure how I can access my inbox using .Net.Mail. Is there a way of doing this?
My code is as fallows
try
{
SmtpClient mySmtpClient = new SmtpClient("smtp.live.com");
// set smtp-client with basicAuthentication
mySmtpClient.UseDefaultCredentials = false;
System.Net.NetworkCredential basicAuthenticationInfo = new
System.Net.NetworkCredential("[email protected]", "password");
mySmtpClient.Credentials = basicAuthenticationInfo;
mySmtpClient.EnableSsl = true;
// add from,to mailaddresses
MailAddress from = new MailAddress("[email protected]");
MailAddress to = new MailAddress("[email protected]");
MailMessage myMail = new System.Net.Mail.MailMessage(from, to);
MailMessage msg;
// set subject and encoding
myMail.Subject = "Test message";
myMail.SubjectEncoding = System.Text.Encoding.UTF8;
// set body-message and encoding
myMail.Body = "<b>Test Mail</b><br>using <b>HTML</b>.";
myMail.BodyEncoding = System.Text.Encoding.UTF8;
// text or html
myMail.IsBodyHtml = true;
mySmtpClient.Send(myMail);
}
catch (SmtpException ex)
{
throw new ApplicationException
("SmtpException has occured: " + ex.Message);
}
Solution 1:[1]
You cannot get emails with SMTP. You need to use IMAP
Consider using a library like https://github.com/andyedinborough/aenetmail AEMail
For more info go here: Accessing Imap in C#
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |