Click here to Skip to main content
14,458,486 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello sir,

how to read mail and download attachments from any company mail id(user1@companyname.gov.in) using c#.net??

personal mail id of company or any organization .

my code is working for gmail.com.
but now i need to work personal mail id plz let me know how can i do using c#.net.

Thanks & Regards,
Pranita Gupta

What I have tried:

private const string _server = "imap.gmail.com";
private const string _user = "user1@gmail.com";
private const string _password = "example@123";

using (ImapClient Client = new ImapClient(_server, 993, _user, _password, AuthMethod.Login, true))
{
IEnumerable uids = Client.Search(SearchCondition.Unseen());

IEnumerable messages = Client.GetMessages(uids, FetchOptions.Normal);
foreach (MailMessage msg in messages)
{
msgFrom = msg.From.ToString();
To = msg.To.ToString();
Subject = msg.Subject;


foreach (Attachment atc in msg.Attachments)
{
SaveMailAttachment(msg.Attachments[0]);
}
}
}
Posted
Comments
Richard MacCutchan 20-Feb-18 4:38am
   
You do it the same way. You just need to know the correct POP or IMAP mail address and port number for the mail system in question.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Email standards are just that - standards. They work no matter what the server. The two common ways to access mail are IMAP and POP3. All you need to do is find out the IMAP server for the mail provider of your personal mail (ask them if you can't find it in your mail client settings) and use those details instead of the gmail ones. You'll need to check your mail provider supports IMAP though, if it doesn't and it only supports POP3 then you'll need to write a POP3 version of your code.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100