My Webapi Code
- [HttpGet]
- public HttpResponseMessage SendMail1(string tomail)
- {
- bool responce = false;
- try
- {
- MailMessage mail = new MailMessage();
- SmtpClient smtpServer = new SmtpClient();
- string password = ConfigurationManager.AppSettings["password"];
- mail.From = new MailAddress(ConfigurationManager.AppSettings["MailFrom"]);
- //string[] toRecipients = vm.ToRecipients.Split(',');
- //foreach (string toRecipient in toRecipients)
- //{
- // if (!string.IsNullOrEmpty(toRecipient))
- // mail.To.Add(new MailAddress(toRecipient));
- //}
- mail.To.Add(new MailAddress(tomail));
- mail.Subject = "subject";
- mail.Body = "body txt";
- //vm.FromRecipients = ConfigurationManager.AppSettings["MailFrom"];
- smtpServer.Host = ConfigurationManager.AppSettings["Host"];
- smtpServer.Port = int.Parse(ConfigurationManager.AppSettings["Port"]);
- smtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
- smtpServer.EnableSsl = bool.Parse(ConfigurationManager.AppSettings["EnableSsl"]);
- smtpServer.Timeout = 100000;
- smtpServer.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["MailFrom"], password);
- smtpServer.Send(mail);
- var Result = this.Request.CreateResponse(HttpStatusCode.OK, responce, new JsonMediaTypeFormatter());
- return Result;
- }
- catch (Exception ex)
- {
- HttpError Error = new HttpError(ex.Message) { { "IsSuccess", false } };
- return this.Request.CreateErrorResponse(HttpStatusCode.OK, Error);
- }
- }
- private async void btnLogin_Clicked(object sender, EventArgs e)
- try
- {
- EmailConfigDetailsVM emildetails = new EmailConfigDetailsVM();
- HttpClient client = new HttpClient();
- string apiUrl = "http://localhost:52869/api/default/sendmail1?tomail=";
- emildetails.ToRecipients ="*********@gmail.com";
- emildetails.Body ="test";
- emildetails.Subject = "test";
- var serializedProduct = JsonConvert.SerializeObject(emildetails);
- var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
- HttpResponseMessage response = client.GetAsync(apiUrl+ "*********@gmail.com").Result;
- if (response.IsSuccessStatusCode)
- {
- DisplayAlert("Alert", "Send Successfully", "OK");
- }
- else
- {
- DisplayAlert("Alert", "Send Failed...", "OK");
- }
- }
- catch (Exception ex)
- {
- string err = ex.InnerException.ToString();
- errormsg.Text = ex.Message.ToString();
- }
Please help me.

Ahsan SiddiquePosted Jun 8, 2018, 9:05 AM