Exemple #1
0
        /// <summary>
        /// Send a new mail Create and send a new mail  - -- Alternate route: &#x60;/dev/characters/{character_id}/mail/&#x60;  Alternate route: &#x60;/legacy/characters/{character_id}/mail/&#x60;  Alternate route: &#x60;/v1/characters/{character_id}/mail/&#x60;
        /// </summary>
        /// <param name="characterId">An EVE character ID</param>
        /// <param name="mail">The mail to send</param>
        /// <param name="datasource">The server name you would like data from</param>
        /// <param name="token">Access token to use if unable to set a header</param>
        /// <returns>int?</returns>
        public int?PostCharactersCharacterIdMail(int?characterId, PostCharactersCharacterIdMailMail mail, string datasource, string token)
        {
            // verify the required parameter 'characterId' is set
            if (characterId == null)
            {
                throw new ApiException(400, "Missing required parameter 'characterId' when calling PostCharactersCharacterIdMail");
            }

            // verify the required parameter 'mail' is set
            if (mail == null)
            {
                throw new ApiException(400, "Missing required parameter 'mail' when calling PostCharactersCharacterIdMail");
            }


            var path = "/characters/{character_id}/mail/";

            path = path.Replace("{format}", "json");
            path = path.Replace("{" + "character_id" + "}", ApiClient.ParameterToString(characterId));

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;

            if (datasource != null)
            {
                queryParams.Add("datasource", ApiClient.ParameterToString(datasource));                      // query parameter
            }
            if (token != null)
            {
                queryParams.Add("token", ApiClient.ParameterToString(token)); // query parameter
            }
            postBody = ApiClient.Serialize(mail);                             // http body (model) parameter

            // authentication setting, if any
            String[] authSettings = new String[] { "evesso" };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling PostCharactersCharacterIdMail: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling PostCharactersCharacterIdMail: " + response.ErrorMessage, response.ErrorMessage);
            }

            return((int?)ApiClient.Deserialize(response.Content, typeof(int?), response.Headers));
        }
Exemple #2
0
        internal async Task <bool> SendMail(DraftMessageSource draft)
        {
            ExceptionHandler.LastException = null;

            if (!await RefreshToken())
            {
                return(false);
            }
            try
            {
                MailApi api = new MailApi();
                PostCharactersCharacterIdMailMail mail = new PostCharactersCharacterIdMailMail
                                                         (
                    Recipients: new List <PostCharactersCharacterIdMailRecipient>(),
                    Subject: draft.Subject,
                    Body: draft.Body
                                                         );

                foreach (var i in draft.Recipients)
                {
                    mail.Recipients.Add(new PostCharactersCharacterIdMailRecipient(
                                            RecipientType: ESIConvert.EntityTypeToRecipientType(i.EntityType),
                                            RecipientId: (int?)i.EntityID));
                }

                await api.PostCharactersCharacterIdMailAsync(
                    characterId : (int?)DBAccount.CharacterId,
                    mail : mail,
                    datasource : ESIConfiguration.DataSource,
                    token : DBAccount.AccessToken);

                return(true);
            }
            catch (Eve.Api.Client.ApiException e)
            {
                ExceptionHandler.HandleApiException(null, e);
                return(false);
            }
            catch (Exception e)
            {
                ExceptionHandler.HandleOtherException(null, e);
                return(false);
            }
        }