class SendEmail
{
static void Main(string[] args)
{
string from = "发件人@yingu.com";
string fromer = "赵海莹";
string to = "收件人@yingu.com";
string toer = "刘春喜";
string Subject = "逾期数据报表";
string file = string.Concat(System.AppDomain.CurrentDomain.BaseDirectory, "ReprotingTemp\\逾期订单列表.xls");
string Body = "逾期数据报表";
//企业邮箱smtp
string SMTPHost = "smtp.qiye.163.com";
string SMTPuser = "发件人@yingu.com";
string SMTPpass = "******(发件人邮箱密码)";
sendmail(from, fromer, to, toer, Subject, Body, file, SMTPHost, SMTPuser, SMTPpass);
}
/// <summary>
/// C#发送邮件函数
/// </summary>
/// <param name="from">发送者邮箱</param>
/// <param name="fromer">发送人</param>
/// <param name="to">接受者邮箱</param>
/// <param name="toer">收件人</param>
/// <param name="Subject">主题</param>
/// <param name="Body">内容</param>
/// <param name="file">附件</param>
/// <param name="SMTPHost">smtp服务器</param>
/// <param name="SMTPuser">邮箱</param>
/// <param name="SMTPpass">密码</param>
/// <returns></returns>
private static bool sendmail(string sfrom, string sfromer, string sto, string stoer, string sSubject, string sBody, string sfile, string sSMTPHost, string sSMTPuser, string sSMTPpass)
{
////设置from和to地址
MailAddress from = new MailAddress(sfrom, sfromer);
MailAddress to = new MailAddress(sto, stoer); ////创建一个MailMessage对象
MailMessage oMail = new MailMessage(from, to); //// 添加附件
if (sfile != "")
{
oMail.Attachments.Add(new Attachment(sfile));
} ////邮件标题
oMail.Subject = sSubject; ////邮件内容
oMail.Body = sBody; ////邮件格式
oMail.IsBodyHtml = false; ////邮件采用的编码
oMail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312"); ////设置邮件的优先级为高
oMail.Priority = MailPriority.High; ////发送邮件
SmtpClient client = new SmtpClient();
////client.UseDefaultCredentials = false;
client.Host = sSMTPHost;
//企业邮箱需设置端口,个人邮箱不需要
client.Port = ;
client.Credentials = new NetworkCredential(sSMTPuser, sSMTPpass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
client.Send(oMail);
return true;
}
catch (Exception err)
{
//Response.Write(err.Message.ToString());
return false;
}
finally
{
////释放资源
oMail.Dispose();
} }
}

C#邮件发送(含附件)的更多相关文章

  1. java mail邮件发送(带附件) 支持SSL

    java mail邮件发送(带附件)有三个类 MailSenderInfo.java package mail; import java.util.Properties; import java.ut ...

  2. System.Net.Mail邮件发送抄送附件(多个)

    /// <summary> /// 邮件发送抄送附件 /// </summary> /// <param name="mailTo">收件人(可 ...

  3. Spring的javaMail邮件发送(带附件)

    项目中经常用到邮件功能,在这里简单的做一下笔记,方便日后温习. 首先需要在配置文件jdbc.properties添加: #------------ Mail ------------ mail.smt ...

  4. C# 解决 邮件发送Excel附件后,excel处于锁定状态

    当使用c#自带的MailMessage类发送excel附件时,再次打开excel会提示处于锁定状态. 解决思路:Attachment是添加附件的类,邮件发送后没有释放该类 public string ...

  5. smtp ssl模式邮件发送与附件添加

    #!/usr/bin/python3 import os import smtplib from email.mime.text import MIMEText from email.mime.mul ...

  6. spring 5.x 系列第20篇 ——spring简单邮件、附件邮件、内嵌资源邮件、模板邮件发送 (代码配置方式)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 邮件发送配置类为com.heibaiyin ...

  7. spring 5.x 系列第19篇 ——spring简单邮件、附件邮件、内嵌资源邮件、模板邮件发送 (xml配置方式)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 邮件发送配置文件为springApplic ...

  8. python SMTP邮件发送(转载)

    Python SMTP发送邮件 SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式. py ...

  9. php邮件发送 phpmailer

    首先要安装phpmailer开源项目. 将class.phpmailer.php转移到php文件夹下, 编写代码: <?php require("class.phpmailer.php ...

随机推荐

  1. 转载pcb设计详细版

    http://www.51hei.com/bbs/dpj-52438-1.html 详细的altium designer制作PCB步骤,按照步骤一步步的学习就会自己制作PCB模型 目 录 实验三  层 ...

  2. Python中*args和**kwargs的使用

    函数定义 使用*args和**kwargs传递可变长参数: *args用作传递非命名键值可变长参数列表(比如元组) **kwargs用作传递键值可变长参数列表(比如字典) 函数入参 *args 传递一 ...

  3. DIV自动居中

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. 【C++】朝花夕拾——中缀转后缀

    对于简单的四则运算而言,后缀表达式可以通过使用栈(stack)快速算出结果 ==================================我是分割线======================= ...

  5. DataWhale学习计划(第六期):python基础任务6

    file-settings 然后选择project Interpreter 把project Interpreter复选框里面的地址换成你安装的anaconda下的python.exe的地址,点击sh ...

  6. JMeter在linux上分布式压测步骤(二)

    哈喽,我又来了~ 前提:三台linux虚拟机,一台作为master,另外两台作为slave. 一.server端 1.修改1099端口,client和server通信的端口,可以不修改,默认就是109 ...

  7. 搭建FileZilla

    FileZilla是C/S架构的,有服务端和客户端 客户端下载地址https://www.filezilla.cn/download/client 安装,一般就下一步下一步了. 服务端下载:https ...

  8. Vue核心知识-computed和watch的使用场景和方法

    https://www.jianshu.com/p/bb7a2244c7ca

  9. ERROR: Field 'PostId' doesn't have a default value Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute statement

    例子: Post p = new Post(); p.setPostId(3); p.setPostName("技术"); 在执行数据保持时提示session.save(p); 的 ...

  10. 题解 洛谷P1501/BZOJ2631【[国家集训队]Tree II】

    Link-Cut-Tree 的懒标记下传正确食用方法. 我们来逐步分析每一个操作. 1:+ u v c:将u到v的路径上的点的权值都加上自然数c; 解决方法: 很显然,我们可以 split(u,v) ...