Posts Tagged ‘Yahoo!’

Free Yahoo! Mail via IMAP

Sunday, May 30th, 2010

It is possible to get direct Yahoo! IMAP access.
Yahoo! operates IMAP servers (imap.mail.yahoo.com in particular), which are globally accessible.

However they require a specific, but non-standard IMAP command to be sent before login is done. The command is: “ID (“GUID” “1″)”

// C#
imap.SendCommand(@"ID (""GUID"" ""1"")");
' VB
imap.SendCommand("ID (""GUID"" ""1"")")

You can also an IMAP over SSL on the standard port 993.

Here’s the full C# version of the code:

using (Imap imap = new Imap())
{
    imap.Connect("imap.mail.yahoo.com");
    imap.SendCommand(@"ID (""GUID"" ""1"")");

	imap.Login("user", "password");

	imap.SelectInbox();
	List<long> uidList = imap.Search(Expression.All());
	foreach (long uid in uidList)
	{
		IMail email = new MailBuilder()
    			.CreateFromEml(imap.GetMessageByUID(uid));
		Console.WriteLine(email.Subject);
	}
	imap.Close(true);
}

and VB.NET version:

Using imap As New Imap()
	imap.Connect("imap.mail.yahoo.com")
	imap.SendCommand("ID (""GUID"" ""1"")")

	imap.Login("user", "password")

	imap.SelectInbox()
	Dim uidList As List(Of Long) = imap.Search(Expression.All())
	For Each uid As Long In uidList
		Dim email As IMail = New MailBuilder() _
			.CreateFromEml(imap.GetMessageByUID(uid))
		Console.WriteLine(email.Subject)
	Next
	imap.Close(True)
End Using

Differences:
- non-standard command ID command is required before any other command.
- Examine explicitly requires CLOSE command (Imap.CloseCurrentFolder), otherwise subsequent SELECT (Imap.Select) has no effect and mailbox is still in read-only state
- IDLE is not implemented.
- SELECT for not existing folder does not create new folder.

You can download the latest version of Mail.dll .NET IMAP client here