Skip to content

Instantly share code, notes, and snippets.

@marcheiligers
Created May 1, 2010 20:38
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/386641 to your computer and use it in GitHub Desktop.
Save marcheiligers/386641 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Text;
using System.Net;
namespace MadMimi
{
class Program
{
static string apiKey = "YOUR MAD MIMI API KEY";
static string username = "YOUR MAD MIMI USER NAME";
static string recipient = "email@domain.com";
static string promotion = "apitest";
static string address = "from@madmimi.com";
static string subject = "Hey! This is an email from the API!";
static string body = "---\nname: Marc";
public static void Main(string[] args) {
Console.WriteLine(SendEmail());
Console.ReadKey();
}
public static string SendEmail() {
try {
WebRequest request = WebRequest.Create("https://madmimi.com/mailer");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string requestData = string.Format(
"username={0}&api_key={1}&promotion_name={2}&recipients={3}&from={4}&body={5}&subject={6}",
username,
apiKey,
promotion,
recipient,
address,
body,
subject
);
Console.WriteLine(requestData);
Console.WriteLine();
byte[] bytes = Encoding.UTF8.GetBytes(requestData);
request.ContentLength = bytes.Length;
using(Stream requestStream = request.GetRequestStream()) {
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
}
string responseData;
WebResponse response = request.GetResponse();
using(StreamReader responseStream = new StreamReader(response.GetResponseStream())) {
responseData = responseStream.ReadToEnd();
responseStream.Close();
}
return responseData;
} catch(WebException webEx) {
return webEx.ToString();
} catch(Exception ex) {
return ex.ToString();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment