Skip to content

Instantly share code, notes, and snippets.

@marcheiligers
Created May 1, 2010 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcheiligers/386473 to your computer and use it in GitHub Desktop.
Save marcheiligers/386473 to your computer and use it in GitHub Desktop.
using System;
using System.Net;
using System.Text;
using System.IO;
namespace MadMimi
{
class Program
{
const string MAD_MIMI_USER_NAME = "YOUR MAD MIMI LOGIN";
const string MAD_MIMI_API_KEY = "YOUR MAD MIMI API KEI";
const string MAD_MIMI_LIST_TO_ADD = "Subscribers";
public static void Main(string[] args)
{
string email = args[0];
Console.WriteLine("Adding " + email + " to your list!");
string result = AddEmailToList(MAD_MIMI_USER_NAME, MAD_MIMI_API_KEY, email, MAD_MIMI_LIST_TO_ADD);
Console.WriteLine(result);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
public static string AddEmailToList(string userName, string apiKey, string emailAddress, string listName) {
try {
WebRequest webRequest = WebRequest.Create("http://madmimi.com/audience_members");
webRequest.Method = "POST";
StringBuilder csv = new StringBuilder();
csv.AppendLine("email,add_list");
csv.AppendLine(emailAddress + "," + listName);
string postData = string.Format("username={0}&api_key={1}&csv_file={2}", userName, apiKey, csv.ToString());
byte[] byteData = UTF8Encoding.UTF8.GetBytes(postData.ToString());
webRequest.ContentLength = byteData.Length;
using (Stream postStream = webRequest.GetRequestStream()) {
postStream.Write(byteData, 0, byteData.Length);
}
using (HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse) {
StreamReader reader = new StreamReader(response.GetResponseStream());
string st = String.Empty;
st = reader.ReadToEnd();
}
return "OK";
} catch (WebException ex) {
return "Web Execption: " + ex.Status + "\n" + ex.Message;
} catch (Exception ex) {
return "General Exception: " + ex.Message;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment