Created
May 1, 2010 20:38
-
-
Save marcheiligers/386641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 protected]"; | |
static string promotion = "apitest"; | |
static string address = "[email protected]"; | |
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