Free Yahoo! Mail via IMAP

Update: Mail.dll issues custom ID command automatically, when it recognizes you are accessing yahoo server.

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 use IMAP over SSL on the standard port 993.

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

using (Imap imap = new Imap())
{
	imap.ConnectSSL("imap.mail.yahoo.com");

	// Not needed as Mail.dll is going to issue this command automatically
	// 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();
}

and VB.NET version:

Using imap As New Imap()
	imap.ConnectSSL("imap.mail.yahoo.com")

	' Not needed as Mail.dll is going to issue this command automatically
	'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()
End Using

Yahoo’s IMAP server 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 stat,
-Yahoo does not support IDLE command,
– SELECT for not existing folder does not create new folder.

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

Tags:     

Questions?

Consider using our Q&A forum for asking questions.

6 Responses to “Free Yahoo! Mail via IMAP”

  1. Buzzknow Says:

    how to do this in PHP?

    thanks

  2. Limilabs support Says:

    @Buzzknow
    I don’t know PHP, but I’m sure that there are components for IMAP in PHP. Remember that you need to issue custom ID command, so the component needs to support that.

    By the way Mail.dll has this already incorporated in the Connect method, so users don’t need to even know about the Yahoo’s non-standard IMAP implementation.

  3. Archana Says:

    If IDLE is not supported by Yahoo then how can we get notifications of new mails

  4. Limilabs support Says:

    @Archana

    In such case, you can only poll (connect, search, disconnect) for messages at specified interval.

  5. Archana Says:

    Hi,
    I keep getting the below exception no matter what i do, this exception occurs only when dealing with yahoo.

    Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

  6. Limilabs support Says:

    @Archana

    This is not the problem with Mail.dll – it’s a problem with your network or yahoo (I can connect, so it’s rather the former).
    Are you sure you have specified Yahoo’s IMAP server address correctly?

    Please consult your network administrator on why you can’t connect to this address.