zoukankan      html  css  js  c++  java
  • C# 发送邮件

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Net;
    using System.Net.Mail;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;


    namespace SendEmailExam
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                txtContent.Text = "<h1>Hello</h1>";
                txtTo.Text = "xxx@163.com";
                txtSubject.Text = "Hello";
                txtCC.Text = "xxx@126.com;xxx@163.com";
            }


            private void btnSend_Click(object sender, EventArgs e)
            {
                SmtpClient sc = new SmtpClient();
                NetworkCredential cred = new NetworkCredential("admin", "admin");
                sc.Credentials = cred;
                sc.Host = "smtp.163.com";
                MailMessage mm = new MailMessage();
                mm.From = new MailAddress("xxx@163.com", "xxx");
                mm.Sender = new MailAddress("xxx@163.com","xxx");
                string[] tos = txtTo.Text.Split(';');
                foreach (string item in tos)
                {
                    mm.To.Add(new MailAddress(item));
                }
                string[] ccs = txtCC.Text.Split(';');
                foreach (string item in ccs)
                {
                    mm.CC.Add(new MailAddress(item));
                }
                mm.Subject = txtSubject.Text;
                mm.Body = txtContent.Text;
                mm.IsBodyHtml = true;
                mm.Priority = MailPriority.High;
                mm.Attachments.Add(new Attachment(txtAccessory.Text));
                sc.Send(mm);
            }

            private void button1_Click(object sender, EventArgs e)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Multiselect = false;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    txtAccessory.Text = ofd.FileName;
                }
            }
        }
    }
  • 相关阅读:
    一、zuul如何路由到上游服务器
    一、hystrix如何集成在openfeign中使用
    一、ribbon如何集成在openfeign中使用
    二、openfeign生成并调用客户端动态代理对象
    一、openfeign的自动配置
    BootStrap【一、概述】
    JavaSpring【七、AspectJ】
    JavaSpring【六、AOP的API】
    JavaSpring【五、AOP基础】
    目录整理
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434766.html
Copyright © 2011-2022 走看看