You use Basic Auth. Basically, you make an initial request, the server replies with 401, and then you send back the password in base64 (in this case over HTTPS).
Note though that:
- The feed only allows you to get trivial info about the account (e.g. new mail). It does not allow you to send messages.
- POP can not be used to send messages either.
- Usually SMTP is used, and it really isn't that hard.
EDIT: Here's an example for authenticating and loading the Atom feed into an XmlDocument. Note though that will only provide read access. Search or ask another question for info on C# and SMTP. The ICertificatePolicy junk was necessary for me as Mono didn't like Google's certificate. It's a quick workaround, not suitable for production.
Okay, since you've clarified you're actually reading mail (and a different component is sending it), I recommend you do use POP.
:
using System;
using System.Net;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
public class GmailFeed
{
private class IgnoreBadCerts : ICertificatePolicy
{
public bool CheckValidationResult (ServicePoint sp,
X509Certificate certificate,
WebRequest request,
int error)
{
return true;
}
}
public static void Main(string[] argv)
{
if(argv.Length != 2)
{
Console.Error.WriteLine("Usage: GmailFeed username password");
Environment.ExitCode = 1;
return;
}
ServicePointManager.CertificatePolicy = new IgnoreBadCerts();
NetworkCredential cred = new NetworkCredential();
cred.UserName = argv[0];
cred.Password = argv[1];
WebRequest req = WebRequest.Create("https://gmail.google.com/gmail/feed/atom");
req.Credentials = cred;
Stream resp = req.GetResponse().GetResponseStream();
XmlReader reader = XmlReader.Create(resp);
XmlDocument doc = new XmlDocument();
doc.Load(reader);
}
}