In. Net, use SendGrid Web Api to send emails (with source code) and sendgridapi

Source: Internet
Author: User

In. Net, use SendGrid Web Api to send emails (with source code) and sendgridapi

SendGridIt is a third-party provider for mail sending services and is widely used abroad. Similar services in China are SendCloud.
SendGridThere are two ways to send emails. One isSMTP API, One isWeb Api.SMTP APIIt is a relatively simple method. As long as we have prepared the Mail Message and sent it directly to the SendGrid Mail server, the SendGrid Mail server will deliver it for us. The other method is Web Api.

Generally, many third-party server providers prohibit external port 25 connections, so you cannot connect to the SendGrid SMTP server to send emails. In this case, Web API is a good choice. SengGrid official has more detailed smtp api Demo. Demo address is https://github.com/sendgrid/sendgrid-csharp because there is no Web API Demo, their own time to write a copy, now share out the https://github.com/justrun1983/sendgrid-csharp-webapi

Used in the codeRestSharp, A very convenient access in. NetRestful API. The complete email sending code is as follows, including cc, bcc, and attachments.

public class WebApiRestSharp  {      private const string ApiWebSite = "https://sendgrid.com";      private const string ApiUrlAddress = "api/mail.send.json";      public static void SendNormalHelloWorldEmail()      {          var client = new RestClient(ApiWebSite);          var request = new RestRequest(ApiUrlAddress, Method.POST);          request.AddParameter("api_user", Config.SendGridName);          request.AddParameter("api_key", Config.SendGridPassword);          request.AddParameter("to[]", Config.ToEmail);          request.AddParameter("cc[]", Config.ToEmail);          request.AddParameter("bcc[]", Config.ToEmail);          request.AddParameter("subject", "Test");          request.AddParameter("from", "test@test.me");          request.AddParameter("text", "HelloWorld1");          request.AddFile("files[2.txt]", @"C:\1.txt");          // execute the request          var response = client.Execute(request);          var content = response.Content; // raw content as string      }  }

 


PHP uses SendGrid to send emails, and the code they send officially cannot be sent.

What are the prompts? Generally, there is SSL verification, and the verification is removed.

If you know the webconfig file, you can download the website source code.

No ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.