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.Text;
    using System.Windows.Forms;
    using AppEmailLibrary;
    using System.Net.Mail;
    using System.Net;

    namespace WindowsFormTestEmail
    {
    public struct MailItem
    {
    public string To;
    public string From;
    public string Subject;
    public string body;
    public string userName;
    public string password;
    public string smtpHost;
    }

    public partial class Form1 : Form
    {
    WinHtmlControl.Editor edit;

    public Form1()
    {
    InitializeComponent();
    edit = new WinHtmlControl.Editor();
    edit.Dock = DockStyle.Top;
    edit.Height = 200;
    this.Controls.Add(edit);


    }

    private void button1_Click(object sender, EventArgs e)
    {
    MailItem mi = new MailItem();
    mi.From = "huangdongkui@tyicd.com";
    mi.To = "huangdongkui@tyicd.com";
    mi.body = edit.DocumentText;
    mi.Subject = "test";
    mi.smtpHost = "smtp.tyicd.com";
    mi.password = "tyicd123";
    mi.userName = "huangdongkui@tyicd.com";

    try
    {
    Send(mi);
    MessageBox.Show("发送成功");
    }
    catch (Exception)
    {

    MessageBox.Show("发送失败");
    }


    }

    private void button2_Click(object sender, EventArgs e)
    {


    }

    public void Send(MailItem aMailItem)
    {
    MailAddress from = new MailAddress(aMailItem.From);
    MailAddress to = new MailAddress(aMailItem.To);
    MailMessage message = new MailMessage(from, to);
    message.Subject = aMailItem.Subject;
    message.IsBodyHtml = true;
    message.Body = aMailItem.body;
    SmtpClient client = new SmtpClient(aMailItem.smtpHost);
    client.Port = 25;
    //设置发送邮件身份验证方式
    //注意如果发件人地址是abc@def.com,则用户名是abc而不是abc@def.com
    client.Credentials = new NetworkCredential(aMailItem.userName, aMailItem.password);
    client.Send(message);
    }
    }
    }

  • 相关阅读:
    msfvenom常用脚本生成
    CC攻击防护方法
    上传漏洞分类
    cmd下载文件(利用powershell)
    发送HTTP请求的新姿势
    (转载).NET Core 深度克隆对象,引用类型的平行世界
    使用VMware安装centos7并配置网络
    (转载)这才是真正的远程开发——VS Code Remote 环境搭建
    (转载)基于Vue,ElementUI开发的一款表单设计器
    (转载)VMWare VMNet 8 的配置使用
  • 原文地址:https://www.cnblogs.com/wolf12/p/3711727.html
Copyright © 2011-2022 走看看