public string CreateAccount(string userName, string nickname, string emailAddress, string mintChipId) { SQLLogger.LogInfo(string.Format("Creating account for user '{0}', nickname '{1}', emailAddress '{2}' and mintChipId '{3}'.", userName, nickname, emailAddress, mintChipId)); if (string.IsNullOrEmpty(userName)) return "<xml><IsValid>0</IsValid><FailureReason>InvalidUserName</FailureReason></xml>"; else if (string.IsNullOrEmpty(userName)) return "<xml><IsValid>0</IsValid><FailureReason>InvalidEmailAddress</FailureReason></xml>"; // check if the user exists already SQL sql = new SQL(); if (sql.IsDuplicateUser(emailAddress)) return "<xml><IsValid>0</IsValid><FailureReason>DuplicateEmailAddress</FailureReason></xml>"; string code = CreateRandomConfirmationCode(); sql.CreateAccount(userName, nickname, emailAddress, code, mintChipId); #region Create Email bool createHTML = false; bool emailCreation = false; string body; if (createHTML) { // tried html and it didn't work, probably just needs more investigation #region HTML body = @"<html><body>Thanks for something Here is your code: 223489 <a href='www.yahoo.com?test=abc>Confirm email</a> Enjoy the app.</body></html>"; #endregion } else { body = string.Format(@"Thanks for creating an account with {0}. To confirm your email address, please enter this code in the application on your device: {1} Enjoy the app.", APP_NAME, code); // Create the web request HttpWebRequest request = WebRequest.Create(string.Format("http://sendgrid.com/api/mail.send.json?to={0}&toname={1}&from=donotreply%40apphb.com&fromname={2}&subject={3}&text={4}&[email protected]&api_key=yg5wbbu6", HttpUtility.UrlEncode(emailAddress), HttpUtility.UrlEncode(userName), HttpUtility.UrlEncode(APP_NAME), HttpUtility.UrlEncode(string.Format("Confirmation code for {0}", APP_NAME)), body)) as HttpWebRequest; // Get response using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { // Get the response stream using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string responseText = reader.ReadToEnd(); if (responseText == "{\"message\":\"success\"}") emailCreation = true; } } // this looks more correct, however the linebreaks don't work //System.Net.HttpWebRequest request = System.Net.WebRequest.Create(string.Format("http://sendgrid.com/api/mail.send.json?to=wolfendaled%40yahoo.com&toname=Dave&from=donotreplywolfendaled%40yahoo.com&fromname=David&subject=Testing123&html={0}&[email protected]&api_key=yg5wbbu6", System.Web.HttpUtility.UrlEncode(body))) as System.Net.HttpWebRequest; } #endregion return string.Format("<xml><IsValid>1</IsValid><EmailCreated>{0}</EmailCreated></xml>", emailCreation ? "1" : "0"); }