The below code is used to send emails through the pardot api.
if (ConfigurationManager.AppSettings.Count > 0)
{
uri = ConfigurationManager.AppSettings["PardotURI"].ToString() + "email/version/4/do/send/prospect_email/" + email;
uri += "?user_key=" + ConfigurationManager.AppSettings["PardotUserKey"].ToString();
uri += "&api_key=" + GetAPIKey() + "&campaign_id=" + GetPardotCampaign("Capis News");
uri += "&from_email=" + ConfigurationManager.AppSettings["FromEmail"].ToString();
uri += "&from_name=" + ConfigurationManager.AppSettings["FromName"].ToString();
uri += "&name=FlyNews - " + DateTime.Now.ToString("MM/dd/yyy h:mm tt");
uri += "&subject=CAPIS: Client Holdings News " + DateTime.Today.ToString("MM/dd/yyyy");
}
try
{
MultipartFormDataContent data = new MultipartFormDataContent();
data.Add(new StringContent(htmlContent), "html_content");
data.Add(new StringContent(textContent), "text_content");
await client.PostAsync(uri, data);
client.Dispose();
}
catch(Exception ex)
It was working great until I noticed a few days ago it started throwing the following exception. Unfortunately it isn't consistent because it will send 30/40 emails but throw exceptions for the other 10, and the number of exceptions each day has been different and for different people. I know the data im sending in the multipartform is large but that shouldn't be part of the uri and unless someone has a 1500 character email the uri should never be too long. Does anyone have any idea of what may be going on? I appreciate any help.
System.UriFormatException: Invalid URI: The Uri string is too long. at System.UriHelper.EscapeString(String input, Int32 start, Int32 end, Char[] dest, Int32& destPos, Boolean isUriString, Char force1, Char force2, Char rsvd) at System.Uri.EscapeDataString(String stringToEscape) at System.Net.Http.FormUrlEncodedContent.Encode(String data) at System.Net.Http.FormUrlEncodedContent.GetContentByteArray(IEnumerable
1 nameValueCollection) at System.Net.Http.FormUrlEncodedContent..ctor(IEnumerable
1 nameValueCollection) at PardotDataAccessLibrary.PardotDataAccess.d__9.MoveNext()