当前位置: 首页 > news >正文

c# SMTP发送邮件

string from = "";
string fromAlias = "MIS-TC";
string[] to = { "" };
string subject = "问题提交";
string body = sb.ToString();
string ipaddr = "smtp.email.qq.com";
int port = 25;
string credit = "";
string password = "";
SqlhelperClass.sqlHelper.SMTP(from, fromAlias, to, subject, body, ipaddr, port, credit, password);

public static void SMTP(string from,string fromAlias, string[] to, string subject, string body, string ipaddr, int port, string creditAccount, string password)
{
    try
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        // 创建电子邮件消息对象
        MailMessage message = new MailMessage
        {
            From = new MailAddress(from, fromAlias)
        };
        foreach (string recipient in to)
        {
            message.To.Add(new MailAddress(recipient));
        }

        // 设置邮件主题和正文
        message.Subject = subject;
        message.Body = body;
        message.BodyEncoding = Encoding.UTF8;

        // 创建SMTP客户端
        SmtpClient client = new SmtpClient(ipaddr, port); // SMTP服务器地址和端口
        client.EnableSsl = false; // 如果服务器支持SSL

        如果SMTP服务器需要身份验证
        client.Credentials = new NetworkCredential(creditAccount, password);


        // 发送邮件
        client.Send(message);
        Serilog.Log.Warning("邮件发送成功!");
    }
    catch (Exception ex)
    {
        Serilog.Log.Error(ex.Message);
    }
}

http://www.lryc.cn/news/435752.html

相关文章:

  • GPU基础 -- 并行化与阿姆达尔定律
  • Lua热更
  • 提升汽车行业软件质量:ASPICE培训的关键实践方法
  • 2024 全新智能识别 API 接口震撼登场
  • 《UniVS: Unified and Universal Video Segmentation with Prompts as Queries》要点提炼
  • 计算机毕业设计选题推荐-推拿知识互动平台-Java/Python项目实战
  • 基于SpringBoot+Vue+MySQL的瑜伽馆管理系统
  • 【MySQL】EXPLAIN(执行计划)关键字是什么?
  • Mybatis两种方式来调用sql语句
  • 第十八节:学习统一异常处理(自学Spring boot 3.x的第五天)
  • flink中slotSharingGroup() 的详解
  • ASPF 技术介绍
  • 77-java 装饰器模式和适配器模式区别
  • 5. Fabric 设置画布大小
  • 240912-通过Ollama实现网站知识总结
  • Debian 包管理工具apt使用
  • 如何模拟一个小程序项目打包的流程
  • 设计模式七大原则详解
  • Navicat On-Prem Server 2.0 | MySQL与MariaDB基础管理功能正式上云
  • 汽车车门的美观与功能:矫平工艺的精细修复
  • 【Python】05.Python 中的列表与元组
  • 【Go】十五、分布式系统、Consul服务注册发现、Nacos配置中心搭建
  • [Linux#48][网络] 令牌环网 | IPv4 | socket 套接字 | TCP | UDP | 网络字节序列
  • Mac OS14外接显示器字体过小和放大字体模糊问题的简单解决
  • Python-pptx:如何在幻灯片中轻松插入与填充表格
  • ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘ (10061)
  • MySQL优化策略(大数据量)
  • 在Excel里制作简单游戏界面
  • 火语言RPA流程组件介绍--鼠标拖拽元素
  • 计算机三级网络技术总结 第十一章网络管理技术