I am getting an exception 'The value cannot be null or empty. (Parameter 'mediaType')' when trying to send an attachment using the RestSharp library. For email sending, I am using MailGun api and the solution is on .NET 7 framework
var client = new RestClient(new Uri(BaseUrl))
{
`Authenticator = new HttpBasicAuthenticator("api", ApiKey)
};
var request = new RestRequest();
request.AddParameter("domain", domain, ParameterType.UrlSegment);
request.Resource = $"{domain}/messages";
request.AddParameter("from", "noreply@smartbroker.com");
request.AddParameter("to", "ahuja.dinesh85@gmail.com");
request.AddParameter("subject", "test subject");
request.AddParameter("html", "hello");
//Attachment
const string fileName = "D:\\ebook.pdf";
request.AddFile("attachment", fileName);
request.Method = Method.Post;
var response = await client.ExecuteAsync(request);
If I comment the attachment code the email goes fine. Do you have any idea what I am doing wrong?
Thanks in advance