Send Email in .NET Core 2.0

在.NET Core 1.0 中,SMTP Client代码并没有被移植,直到.NET Core 2.0的发布。使用下面的代码:

static void Main(string[] args)
{
    SmtpClient client = new SmtpClient("smtp.163.com");
    client.UseDefaultCredentials = false;
    client.Credentials = new NetworkCredential("bidianqing123", "your password");

    MailMessage mailMessage = new MailMessage();
    mailMessage.From = new MailAddress("[email protected]");
    mailMessage.To.Add("[email protected]");
    mailMessage.Body = "body";
    mailMessage.Subject = "subject";
    client.Send(mailMessage);
    Console.WriteLine("发送成功");
    Console.ReadKey();
}

一定要确保框架是.NET Core 2.0,否则你将无法使用它。

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

</Project>
时间: 2024-10-14 05:24:03

Send Email in .NET Core 2.0的相关文章

Sending Email In .NET Core 2.0

Consider the following written in .NET Core 2.0. 1 SmtpClient client = new SmtpClient("smtp.exmail.qq.com", 587) 2 { 3 UseDefaultCredentials = true, 4 Credentials = new NetworkCredential("[email protected]", "yHbgby"), 5 Enab

Professional C# 6 and .NET Core 1.0 - Chapter 41 ASP.NET MVC

What's In This Chapter? Features of ASP.NET MVC 6 Routing Creating Controllers Creating Views Validating User Inputs Using Filters Working with HTML and Tag Helpers Creating Data-Driven Web Applications Implementing Authentication and Authorization W

用ASP.NET Core 1.0中实现邮件发送功能

准备将一些项目迁移到 asp.net core 先从封装类库入手,在遇到邮件发送类时发现在 asp.net core 1.0中并示提供SMTP相关类库,于是网上一搜发现了MailKit 好东西一定要试一下,何况是开源,下面是代码可实现SMTP邮件发送: using MailKit.Net.Smtp; using MailKit.Security; using MimeKit; using System.Threading.Tasks; namespace ConsoleApp1 { public

Securing ASP.NET Core 2.0 Applications with JWTs

A Quick Introduction to JWTs JSON Web Tokens, often shortened with JWTs, are gathering more and more popularity in the Web environment. It is an open standard that allows transmitting data between parties as a JSON object in a compact and secure way.

从头编写 asp.net core 2.0 web api 基础框架 (3)

原文:从头编写 asp.net core 2.0 web api 基础框架 (3) 第一部分:http://www.cnblogs.com/cgzl/p/7637250.html 第二部分:http://www.cnblogs.com/cgzl/p/7640077.html Github源码地址:https://github.com/solenovex/Building-asp.net-core-2-web-api-starter-template-from-scratch 之前我介绍完了asp

丙申年把真假美猴王囚禁在容器中跑 ASP.NET Core 1.0

丙申年把真假美猴王囚禁在容器中跑 ASP.NET Core 1.0? 警告 您当前查看的页面是未经授权的转载! 如果当前版本排版错误,请前往查看最新版本:http://www.cnblogs.com/qin-nz/p/aspnetcore-run-on-mono-in-year-of-monkey.html 提示 更新时间:2016年02月07日. 各位程序媛/程序猿们,猴年快乐. 相信不少媛/猿都是被标题吸引来的,那我我先解释下标题. 提示 本文是一篇半科普文,不对技术细节进行深入探究. 标题

一起学ASP.NET Core 2.0学习笔记(二): ef core2.0 及mysql provider 、Fluent API相关配置及迁移

不得不说微软的技术迭代还是很快的,上了微软的船就得跟着她走下去,前文一起学ASP.NET Core 2.0学习笔记(一): CentOS下 .net core2 sdk nginx.supervisor.mysql环境搭建搭建好了.net core linux的相关环境,今天就来说说ef core相关的配置及迁移: 简介: Entity Framework(以下简称EF) 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapping) 解决方案,EF Core是Entity

初识ASP.NET Core 1.0

本文将对微软下一代ASP.NET框架做个概括性介绍,方便大家进一步熟悉该框架. 在介绍ASP.NET Core 1.0之前有必要澄清一些产品名称及版本号.ASP.NET Core1.0是微软下一代ASP.NET 框架,在这之前ASP.NET版本稳定在ASP.NET  4.6,对应的.NET Framework版本为.net 4.6.1. 曾经一段时间微软将下一代ASP.NET 命名为ASP.NET 5和MVC 6,在ASP.NET 5 is dead – Introducing ASP.NET

Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email

Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email. (文档 ID 604763.1) 转到底部 修改时间:2014-5-13类型:PROBLEM 为此文档评级 通过电子邮件发送此文档的链接 在新窗口中打开文档 In this Document   Symptoms   Cause   Solution   References APPLIES TO: PL/S