I am looking for a library or a simple way to open a hotmail inbox and read new and old emails. A sample code would be much appreciated.
Thanks SOF.
I had the same problem and the gentleman from asp.net show me this link to go download openpop: http://hpop.sourceforge.net/
The link has a test project. But all I needed was:
Pop3Client pop3Client = new Pop3Client();
pop3Client.Connect("pop3.live.com", 995, true);
pop3Client.Authenticate("user", "password");
Message message = pop3Client.GetMessage(10);
string messageText = message.ToMailMessage().Body;
if you want to go with imap protocol ... this may help : using c# .net librarires to check for IMAP messages from gmail servers
Related
I have a web application that sends emails from one gmail account to another to notify me that an event has occurred on my website. Working locally it works as intended, I am able to send emails with a body, subject and attachments as expected. However, When I deploy my application to azure the attachments are removed, there isn't anything suggesting that the email was modified on either email.
Here is the code that is used to send the email:
using (MailMessage mail = new MailMessage())
{
try
{
if (userImageStream.Length > 0)
{
mail.Attachments.Add(new Attachment(userImageStream, "Customer.jpg", "image/jpeg"));
}
if (exImageStream.Length > 0)
{
mail.Attachments.Add(new Attachment(exImageStream, "Example.jpg", "image/jpeg"));
}
}
catch (Exception ex) { }
mail.From = new MailAddress(maileraddress);
mail.To.Add(mailTarget);
mail.Subject = "subject";
mail.Body = mailBody;
mail.IsBodyHtml = true;
using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
{
smtp.Credentials = new System.Net.NetworkCredential(maileraddress, password);
smtp.EnableSsl = true;
await smtp.SendMailAsync(mail);
}
}
I have tried quite a few things programmatically. I can say that for sure the files are uploaded either to a stream or file (depending on configuration). I tried making a outlook account with the gmail email and using smtp.live.com which also didn't work. I think this has something to do with azure (which i have just started using a day or two ago) and I have no idea where to go or what to do. I have seen something about this problem occurring when people are downloading from blobs (I don't know what that is, and i really don't want to yet if possible) but I couldn't figure out how to leverage that answer to solve my problem. I really am stuck here and any help is greatly appreciated. Please keep in mind that I am a novice programmer and my knowledge of azure is basically just enough to get a website up.
After some more testing it appears the files are still null after upload. I'm not saving to file system only to a variable so I'm still confused.
Update: managed to ssh into server, it appears the files aren't being saved. I'm still looking into it any insight will be appreciated.
Can anyone answer if it is even possible to deal with a file that is temporarily uploaded with out being required to use blob storage?
Apparently I dont need to use blob storage but I cant get it to save anyways even with webrootpath. I decided to go back to using streams again and it sends a file but it cant be opened, I'm guessing it might be fixed but I'm not sure. I'll update if I find solution.
Finally- after going back to using streams it works. I'm frustrated that I missed it before chasing my tail but here I am and its finished.
I am trying to use c# Microsoft Outlook Interop to send an email with voting options. The only issue is that I want to not receive the response but rather the responses be sent to another email address (not mine).
Currently my code sends the voting responses to myself which is not what i want. I want to send it to a given email that I provide in string format.
This is my existing code:
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mail = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mail.Body= "hi";
mail.VotingOptions = "Cheese;Combo;Maybe;";
mail.Recipients.Add("abc#gmail.com");
mail.Send();
Use MailItem.ReplyRecipients.Add.
I was looking around and there is couple of projects but they all seem to be outdated,
should i use those? or is there a new out the box pop3 class that I can't find in msdn.
anyhow i'm not doing a client that needs to send out so no SMTP is needed, more like a bot that sorts out the emails and reads them., any ideas?
Cheers!
Take a look at Mail.dll POP3 client. It supports SSL, is easy to use, and supports parsing complex MIME structures:
using(Pop3 pop3 = new Pop3())
{
pop3.ConnectSSL("pop3.server.com");
pop3.Login("user", "password");
foreach (string uid in pop3.GetAll())
{
IMail email = new MailBuilder()
.CreateFromEml(pop3.GetMessageByUID(uid));
Console.WriteLine(email.Subject);
}
pop3.Close(true);
}
Please note that this is a commercial product that I developed
You can download Mail.dll here:
http://www.lesnikowski.com/mail/
I discovered OpenPOP on another thread, which seems to be my library of choice at the moment for this very task.
I built one a few years back that's posted on code project and it is dated (http://www.codeproject.com/KB/IP/NetPopMimeClient.aspx). If you are interested I can send you a copy of the latest source code which was never posted to CP.
I ended up using Dart Mail as a replacement for the solution I developed posted on CP. The main reason I ended up using Dart Mail is for the Mime Parsing facilities that it has which really ended up being the main problem with the solution I developed. IIRC Dart Mail is pretty reasonable and may be worth a look if you need something that is robust.
I am looking for a .NET Pop3 Email Library.
I need be able to read from a Pop3 account where I'll copy all the mail to a local database.
A paid library is fine
I found aspnetPop3 do anyone know if this any good
Any help would be a great help
I've tried a few, and settled on Lesnikowski Mail from http://www.lesnikowski.com/mail/. Its object model is a nice fit for how email really works; other libraries I used tried to hide the details but ended up just getting in the way. The Lesnikowski library was robust enough to work across hundreds of installations, talking to many different varieties of POP3 server.
The Indy library was an old favorite of Delphi developers for sockets programming, including SMTP and POP3. It's now been ported to C# and open sourced. You might want to check it out. One word of warning: there isn't a lot of documentation available, but most of the code is quite self-explanatory...
http://www.indyproject.org/SocketsCLR/index.EN.aspx
Our Rebex Secure POP3 might be fine for you. It's actively developed since 2006.
Following code shows how to to download all messages from the POP3 server and save them to the database:
// create client, connect and log in
Pop3 client = new Pop3();
client.Connect("pop3.example.org");
client.Login("username", "password");
// get message list - full headers
Pop3MessageCollection messageList = client.GetMessageList();
foreach (Pop3MessageInfo messageInfo in messageList)
{
// download message
MailMessage message = client.GetMailMessage(messageInfo.SequenceNumber);
// store it to the database...
// depends on your DB structure.
// message.Save(stream) or message.ToByteArray() would be handy
...
}
client.Disconnect();
I can recommend http://www.chilkatsoft.com/ and their mail components.
Not only will it allow you to send out email (plain text/encrypted/html) it also has POP3/IMAP components. There are tonnes of examples in a number of different languages and they are great on support if you should need it.
It also has a 30 day free trial (full funationality)
MailKit.Net, the official Microsoft replacement for SmtpClient also has support for Pop3 and Imap. It can be downloaded as a nuget package.
Similar question as this one but for a Microsoft Environment.
Email --> Exchange Server -->[something]
For the [something] I was using Outlook 2003 & C# but it feels messy (A program is trying to access outlook, this could be a virus etc)
Microsoft.Office.Interop.Outlook.Application objOutlook = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace objNS = objOutlook.GetNamespace("MAPI");
objNS.Logon("MAPIProfile", "MAPIPassword", false, true);
Is this the best way to do it? Is there a better way of retrieving and processing emails in a Microsoft environment???
This library provides you basic support for the POP3 protocol and MIME, you can use it to check specified mailboxes and retrieve emails and attachments, you can tweak it to your needs.
Here is another library, this one is for the IMAP protocol, it's very basic but also allows you to fetch complete messages, including attachments...
I've been happy with the Rebex components which provide IMAP access. Of course you need to ensure your Exchange administrators will open an IMAP port on your Exchange servers.
Using IMAP is a way to go. You can use Mail.dll IMAP component:
using(Imap imap = new Imap())
{
imap.Connect("imap.company.com");
imap.UseBestLogin("user", "password");
imap.SelectInbox();
List<long> uids = imap.Search(Flag.Unseen);
foreach (long uid in uids)
{
var eml = imap.GetMessageByUID(uid);
IMail message = new MailBuilder()
.CreateFromEml(eml);
Console.WriteLine(message.Subject);
Console.WriteLine(message.Text);
}
imap.Close(true);
}
You can download it here: Mail.dll email component.
I am trying http://csharpopensource.com/openpopdotnet.aspx, it have been recently updated and it is not bad. It lack good documentation but it also work with gmail/ssl.