Search code examples
c#emailsendmailmailjet

how to know email status (mailject)


I'm using Mailjet SMTP to send email's. Now, i want to verify if email was send or not. Mailjet have this email status , but how i can have access to this information? Mailjet have too this API, but this in php...

If i use DeliveryNotificationOptions can resolve this? Something like this:

mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure | DeliveryNotificationOptions.Delay;

Solution

  • I can communicate with API Mailjet like:

    Uri address = new Uri("http://api.mailjet.com/0.1/reportEmailsent");
    HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
    request.Method = "GET";
    request.KeepAlive = true;
    request.Headers.Add("apiKey", "numberapiKey");
    request.Headers.Add("secretKey", "numbersecretKey");
    request.Credentials = new NetworkCredential("apiKey", "serialKey");
    request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
    request.Accept = "application/x-www-form-urlencoded; charset=UTF-8";
    

    Now getting response:

    // Get response
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
       Stream ResponseStream = null;
       ResponseStream = response.GetResponseStream();
       int responseCode = (int)response.StatusCode;
       string responseBody = ((new StreamReader(ResponseStream)).ReadToEnd());
    }