How To Send Emails With .NET in Under 10 Minutes - Tutorial by Mailtrap

Поделиться
HTML-код
  • Опубликовано: 30 сен 2024

Комментарии • 22

  • @mailtrap.
    @mailtrap.  Год назад +3

    Join us at Mailtrap to learn more about email deliverability, email security, and email infrastructure. This .NET tutorial will teach you to send emails via SMTP and API. Do you have any other questions about how to send emails in .Net? Let us know in the comments section.

  • @MuqriHafiybinMazli
    @MuqriHafiybinMazli 24 дня назад

    i keep getting false, it is because i havent create an account with mailtrap?

    • @mailtrap.
      @mailtrap.  24 дня назад

      Thank you for watching! Please, provide us with more context so we would be able to give you assistance. Where do you get "false", what step are you talking about? Let us know

  • @056_bambangpriyambodo5
    @056_bambangpriyambodo5 7 месяцев назад +1

    can I see what inside file IMailService and MailService?

    • @mailtrap.
      @mailtrap.  7 месяцев назад

      Hey, thanks for asking. Please, check our article to find your answer:
      l.rw.rw/59e2wn2yjw
      Stay tuned!

  • @starsfrkaz
    @starsfrkaz 5 месяцев назад

    Hello! You talked about ApiToken and ApiBaseUrl properties and it ould be found in the settings of the account. What do you mean by account? How can we search for the account? I apologize if the question sounds naive but I'm a junior developer and I'm trying to learn. Ty!

    • @mailtrap.
      @mailtrap.  5 месяцев назад

      Hey! Thanks for asking! No problem, we are here to help.
      So we talk about an account with an email service provider that offers an API for sending emails. In our case, this is Mailtrap. And you can find these parameters under the API tab in Mailtrap.
      In this example, you would replace "YourApiToken" and "api.example.com" with your actual API token and base URL provided by Mailtrap:
      using System;
      using System.Net.Http;
      using System.Threading.Tasks;
      public class EmailSender
      {
      private readonly HttpClient httpClient;
      private readonly string apiToken;
      private readonly string apiBaseUrl;
      public EmailSender(string apiToken, string apiBaseUrl)
      {
      this.apiToken = apiToken;
      this.apiBaseUrl = apiBaseUrl;
      httpClient = new HttpClient();
      httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiToken}");
      }
      public async Task SendEmailAsync(string recipient, string subject, string body)
      {
      var payload = new
      {
      To = recipient,
      Subject = subject,
      Body = body
      };
      var requestUri = new Uri($"{apiBaseUrl}/send-email");
      var response = await httpClient.PostAsJsonAsync(requestUri, payload);
      if (!response.IsSuccessStatusCode)
      {
      throw new Exception($"Failed to send email: {response.ReasonPhrase}");
      }
      }
      }
      Hope this helps! Let us know how it goes.
      Also, stay with Mailtrap channel for more things email!

  • @sarathsanil
    @sarathsanil Год назад

    does this work even if we have 2 factor authentication on the mail account? If no, what would be the work around?

    • @mailtrap.
      @mailtrap.  Год назад

      Thank you for your attention to our videos! It should work

    • @deepakjoyjose8189
      @deepakjoyjose8189 9 месяцев назад

      You just need to create an app specific password under you 2-factor authentication settings.

  • @mohmdali5660
    @mohmdali5660 Год назад

    Can you explain to us how we work in MVC Core 6 ?

    • @mailtrap.
      @mailtrap.  Год назад +1

      Sure thing. Let's wait for the new tutorials

    • @attilaguba856
      @attilaguba856 10 месяцев назад

      That would be amazing with Asp net core MVC too.

  • @toughman4734
    @toughman4734 11 месяцев назад

    Hello, Is it free or priced ?

    • @mailtrap.
      @mailtrap.  11 месяцев назад

      What exactly are you asking about?

    • @attilaguba856
      @attilaguba856 10 месяцев назад

      There is a free version I think for 1000email/month but need to double check their packages!