public static void sendEmail(string toAddress, string emailbody)
        {

            var fromAddress = ConfigurationManager.AppSettings["EmailAddress"];

            string fromPassword = ConfigurationManager.AppSettings["EmailPassword"].ToString();

            const string subject = "Job Recommendation";

var smtp = new SmtpClient

                           {

                               Host = ConfigurationManager.AppSettings["SmtpServer"].ToString(),

                               Port = int.Parse(ConfigurationManager.AppSettings["SmtpPort"]),

                               EnableSsl = true,

                               DeliveryMethod = SmtpDeliveryMethod.Network,

                               UseDefaultCredentials = false,

                               Credentials = new NetworkCredential(fromAddress, fromPassword)

                           };

            using (var message = new MailMessage(fromAddress, toAddress, subject, HttpUtility.HtmlEncode(emailbody)))

            {

                smtp.Send(message);

            }

}

<add key="EmailAddress" value="**********@gmail.com"/>//Email Address
  <add key="EmailPassword" value="*********"/>           //Emial PWD
  <add key="SmtpServer" value="smtp.gmail.com"/>
  <add key="SmtpPort" value="587"/>

<--带附件版本->

var fromAddress = "allenyinj@gmail.com";
                string fromPassword = "yj1989120";
                const string subject = "CV";

var smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(fromAddress, fromPassword)
                };
                MailMessage email=new MailMessage(fromAddress, "allen.yin.jun@gmail.com");
                email.Subject = "INLINE attachment TEST";
                email.IsBodyHtml = true;
                string attachmentPath = "C:\\3.jpeg";
                Attachment inline = new Attachment(attachmentPath);
                inline.ContentDisposition.Inline = true;
                inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
                //inline.ContentId = "1";
                //inline.ContentType.MediaType = "image/png";
                inline.ContentType.Name = Path.GetFileName(attachmentPath);
                email.Attachments.Add(inline);
                email.Body = "test";
                smtp.Send(email);

email.Dispose();

//如果没有路径,用Stream

Attachment letter = new Attachment(FileUploadLetter.FileContent, FileUploadLetter.PostedFile.ContentType);
                letter.ContentDisposition.Inline = true;
                letter.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
                //inline.ContentId = "1";
                letter.ContentType.MediaType = FileUploadLetter.PostedFile.ContentType;
                letter.ContentType.Name = Path.GetFileName(FileUploadLetter.PostedFile.FileName);
                letter.Name = Path.GetFileName(FileUploadLetter.PostedFile.FileName);

.net SMTP发送Email 更新(可带附件)的更多相关文章

  1. python实现邮件发送完整代码(带附件发送方式)

    实例一:利用SMTP与EMAIL实现邮件发送,带附件(完整代码) __author__ = 'Administrator'#coding=gb2312 from email.Header import ...

  2. [Java] JavaMail 发送 html 格式、带附件的邮件

    本案例演示发送 html 格式,可带附件的邮件发送.发送纯文本邮件的例子可参照上一篇博文JavaMail 简单案例. EmailHelper, Email 的帮助类,向帮助类提供 SMTP 服务器域名 ...

  3. smtp发送html报告与日志附件图片png

    1.非ssl发送: 授权码机制,开启smtp,获取授权码以qq邮箱为例: 附件展示: #!/usr/bin/python3 import os import smtplib from email.mi ...

  4. ThinkPHP5 封装邮件发送服务(可带附件)

    1.Composer 安装 phpmailer composer require phpmailer/phpmailer 2.ThinkPHP 中封装邮件服务类 我把它封装在扩展目录 extend/M ...

  5. Oracle PLSQL通过SMTP发送E-MAIL邮件代码

    登录到SMTPserver发送邮件,支持HTML CREATE OR REPLACE PROCEDURE send_mail(        p_recipient VARCHAR2, -- 邮件接收 ...

  6. python学习笔记(SMTP邮件发送:带附件)

    博主有段时间没有更新博客了 先整理一个之前整理过的SMTP邮件发送,这次是带附件的功能 #!/usr/bin/env python # -*- coding: utf_8 -*- from email ...

  7. 利用springframework+javax.mail发邮件(普通邮件、带附件邮件、HTML格式邮件)

    Spring提供了发送电子邮件的支持,可以发送普通邮件.带附件邮件.HTML格式邮件,甚至还可以使用Velocity模板定制化邮件内容. 一.引入相关的库 1 2 3 4 5 6 7 8 9 10 1 ...

  8. python发送邮件(带附件)

    python通过stmp发送qq邮件,带附件 import smtplib from email.mime.multipart import MIMEMultipart from email.mime ...

  9. python 发送email邮件带附件

    EMAIL功能实现: 1.发送EMAIL带附件,并且带压缩文件夹做为附件 #_*_coding:utf-8_*_ import smtplib from email.mime.text import ...

随机推荐

  1. go之匿名字段

    struct,定义的时候是字段名与其类型一一对应,实际上Go支持只提供类型,而不写字段名的方式,也就是匿名字段,也称为嵌入字段. 当匿名字段是一个struct的时候,那么这个struct所拥有的全部字 ...

  2. 访问祖先类的虚方法(直接访问祖先类的VMT,但是这种方法在新版本中未必可靠)

    访问祖先类的虚方法 问题提出 在子类覆盖的虚方法中,可以用inherited调用父类的实现,但有时候我们并不需要父类的实现,而是想跃过父类直接调用祖先类的方法. 举个例子,假设有三个类,实现如下: t ...

  3. [docker]docker的四种网络方式

    声明: 本博客欢迎转发,但请保留原作者信息! 博客地址:http://blog.csdn.net/halcyonbaby 内容系本人学习.研究和总结,如有雷同,实属荣幸! bridge方式(默认) H ...

  4. Java 螺纹第三版 第一章Thread介绍、 第二章Thread创建和管理学习笔记

    第一章 Thread导论 为何要用Thread ? 非堵塞I/O      I/O多路技术      轮询(polling)      信号 警告(Alarm)和定时器(Timer) 独立的任务(Ta ...

  5. 解决编译apache出现的问题:configure: error: APR not found . Please read the documentation - ____哊.時^随记 - 51CTO技术博客

    解决编译apache出现的问题:configure: error: APR not found . Please read the documentation - ____哊.時^随记 - 51CTO ...

  6. easy_install MySQL-python

    python - Why can't easy_install find MySQLdb? - Stack Overflow easy_install MySQL-python

  7. [半原创]指纹识别+谷歌图片识别技术之C++代码

    原地址:http://blog.csdn.net/guoming0000/article/details/8138223 以前看到一个http://topic.csdn.net/u/20120417/ ...

  8. Kaggle—Digit Recognizer竞赛

    Digit Recognizer 手写体数字识别  MNIST数据集 本赛 train 42000样例 test 28000样例,原始MNIST是 train 60000 test 10000 我分别 ...

  9. LVS的调度算法分析

    LVS调度算法 一.静态调度算法 1.  rr(round robin)轮询调度,即调度器将客户端的请求依次的传递给内部的服务器,从1到N,算法简洁,无须记录状态,但是不考虑每台服务器的性能. 配置如 ...

  10. Cocos2dx项目启程二 之 封装属于我的按钮类

    不知道为什么,很讨厌cocos2dx的 各菜单类,比如按钮:如果一张图片上就已经有按钮的几个状态了,我还是要创建多张资源图片, 最起码要指定这张图片上哪块区域是这个普通状态,哪块区域是那个选中状态.. ...