邮件发送 emailsend .net开发
protected void Button1_Click(object sender, EventArgs e)
{
MailSender.Send("lizihong3@163.com", "产品邮件", "产品内容");
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Configuration;
using System.Web;
using System.IO;
using System.Net;
using System.Net.Mail;
namespace Maticsoft.Common
{
public class MailSender
{
public static void Send(string server, string sender, string recipient, string subject,
string body, bool isBodyHtml, Encoding encoding, bool isAuthentication, params string[] files)
{
SmtpClient smtpClient = new SmtpClient(server);
MailMessage message = new MailMessage(sender, recipient);
message.IsBodyHtml = isBodyHtml;
message.SubjectEncoding = encoding;
message.BodyEncoding = encoding;
message.Subject = subject;
message.Body = body;
message.Attachments.Clear();
if (files != null && files.Length != 0)
{
for (int i = 0; i < files.Length; ++i)
{
Attachment attach = new Attachment(files[i]);
message.Attachments.Add(attach);
}
}
if (isAuthentication == true)
{
smtpClient.Credentials = new NetworkCredential(SmtpConfig.Create().SmtpSetting.User,
SmtpConfig.Create().SmtpSetting.Password);
}
smtpClient.Send(message);
}
public static void Send(string recipient, string subject, string body)
{
Send(SmtpConfig.Create().SmtpSetting.Server, SmtpConfig.Create().SmtpSetting.Sender, recipient, subject, body, true, Encoding.Default, true, null);
}
public static void Send(string Recipient, string Sender, string Subject, string Body)
{
Send(SmtpConfig.Create().SmtpSetting.Server, Sender, Recipient, Subject, Body, true, Encoding.UTF8, true, null);
}
static readonly string smtpServer = System.Configuration.ConfigurationManager.AppSettings["SmtpServer"];
static readonly string userName = System.Configuration.ConfigurationManager.AppSettings["UserName"];
static readonly string pwd = System.Configuration.ConfigurationManager.AppSettings["Pwd"];
static readonly int smtpPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpPort"]);
static readonly string authorName = System.Configuration.ConfigurationManager.AppSettings["AuthorName"];
static readonly string to = System.Configuration.ConfigurationManager.AppSettings["To"];
public void Send(string subject, string body)
{
List<string> toList = StringPlus.GetSubStringList(StringPlus.ToDBC(to), ',');
OpenSmtp.Mail.Smtp smtp = new OpenSmtp.Mail.Smtp(smtpServer, userName, pwd, smtpPort);
foreach (string s in toList)
{
OpenSmtp.Mail.MailMessage msg = new OpenSmtp.Mail.MailMessage();
msg.From = new OpenSmtp.Mail.EmailAddress(userName, authorName);
msg.AddRecipient(s, OpenSmtp.Mail.AddressType.To);
//设置邮件正文,并指定格式为 html 格式
msg.HtmlBody = body;
//设置邮件标题
msg.Subject = subject;
//指定邮件正文的编码
msg.Charset = "gb2312";
//发送邮件
smtp.SendMail(msg);
}
}
}
public class SmtpSetting
{
private string _server;
public string Server
{
get { return _server; }
set { _server = value; }
}
private bool _authentication;
public bool Authentication
{
get { return _authentication; }
set { _authentication = value; }
}
private string _user;
public string User
{
get { return _user; }
set { _user = value; }
}
private string _sender;
public string Sender
{
get { return _sender; }
set { _sender = value; }
}
private string _password;
public string Password
{
get { return _password; }
set { _password = value; }
}
}
public class SmtpConfig
{
private static SmtpConfig _smtpConfig;
private string ConfigFile
{
get
{
string configPath = ConfigurationManager.AppSettings["SmtpConfigPath"];
if (string.IsNullOrEmpty(configPath) || configPath.Trim().Length == 0)
{
configPath = HttpContext.Current.Request.MapPath("/Config/SmtpSetting.config");
}
else
{
if (!Path.IsPathRooted(configPath))
configPath = HttpContext.Current.Request.MapPath(Path.Combine(configPath, "SmtpSetting.config"));
else
configPath = Path.Combine(configPath, "SmtpSetting.config");
}
return configPath;
}
}
public SmtpSetting SmtpSetting
{
get
{
XmlDocument doc = new XmlDocument();
doc.Load(this.ConfigFile);
SmtpSetting smtpSetting = new SmtpSetting();
smtpSetting.Server = doc.DocumentElement.SelectSingleNode("Server").InnerText;
smtpSetting.Authentication = Convert.ToBoolean(doc.DocumentElement.SelectSingleNode("Authentication").InnerText);
smtpSetting.User = doc.DocumentElement.SelectSingleNode("User").InnerText;
smtpSetting.Password = doc.DocumentElement.SelectSingleNode("Password").InnerText;
smtpSetting.Sender = doc.DocumentElement.SelectSingleNode("Sender").InnerText;
return smtpSetting;
}
}
private SmtpConfig()
{
}
public static SmtpConfig Create()
{
if (_smtpConfig == null)
{
_smtpConfig = new SmtpConfig();
}
return _smtpConfig;
}
}
}
邮件发送 emailsend .net开发的更多相关文章
- J2EE 邮件发送那些事儿
距离自己写的关于java邮件发送的第一篇博客已经有很长一段时间了,现在回过头看看.虽然代码质量方面有待提高,整体结构也不怎样,但是基本思路和过程还是比较纯的.现在有空写写J2EE中邮件发送的开发,实际 ...
- .NET开发邮件发送功能的全面教程(含邮件组件源码)
今天,给大家分享的是如何在.NET平台中开发“邮件发送”功能.在网上搜的到的各种资料一般都介绍的比较简单,那今天我想比较细的整理介绍下: 1) 邮件基础理论知识 2) ...
- 【干货】.NET开发通用组件发布(二) 邮件发送组件
组件介绍和合作开发 http://www.cnblogs.com/MrHuo/p/MrHuoControls.html 邮件发送组件 邮件发送组件采用常用的SMTP发送方式,需要添加以下格式的配置文件 ...
- .NET开发邮件发送功能
.NET开发邮件发送功能 今天,给大家分享的是如何在.NET平台中开发“邮件发送”功能.在网上搜的到的各种资料一般都介绍的比较简单,那今天我想比较细的整理介绍下: 1) 邮件基础理论知 ...
- iOS开发-邮件发送
Web开发的时候邮箱注册登录是必不可少的,手机号可以更换,不过相对而言,邮箱只是用于比较重要的时候用到,比如找工作的时候必填的邮箱,注册网站会员的邮箱验证.现在的手机和Web的其实操作是一样的,大多数 ...
- QT开发之旅四邮件发送工具
终于有了一个晚上安静的写写程序,最近一直忙着公司商务上的事情,一直想用QT实现一个调用最底层socket通信来实现的邮件发送程序,以前用C#写过,微软都封装好的,不知道底层是如何实现的,只知道调用方法 ...
- 循序渐进BootstrapVue,开发公司门户网站(3)--- 结合邮件发送,收集用户反馈信息
在我们公司门户网站里面,如果有需要,我们可以提供一个页面给用户反馈信息,以便获得宝贵的用户信息反馈或者一些产品咨询的记录,一般这个结合邮件发送到负责人的邮箱即可.本篇随笔结合后端发送邮件的操作,把相关 ...
- 测试开发【提测平台】分享11-Python实现邮件发送的两种方法实践
微信搜索[大奇测试开],关注这个坚持分享测试开发干货的家伙. 按照开发安排,本篇本应该是关于提测页面的搜索和显示实现,怕相似内容疲劳,这期改下内容顺序,将邮件服务的相关的提前,在之前的产品需求和原型中 ...
- AspNetCore 目前不支持SMTP协议(基于开源组件开发邮件发送,它们分别是MailKit 和 FluentEmail )
net所有的功能都要重新来一遍,集成众多类库,core任重道远,且发展且努力!! 我们都知道,很多的邮件发送都是基于这个SMTP协议,但现在的.net core对这方面还不太支持,所以我们选择这两个组 ...
随机推荐
- Oracle 查询时间在当天的数据
要实现这个功能需要用到trunc这个函数对时间的操作 select trunc(sysdate) from dual --2014-12-27 今天的日期为2014-12-27 select trun ...
- javascript块级作用域
在c/java中,拥有块级作用域的概念,大括号内就是一个块级作用域,在块级作用域内声明的变量,块以外不可见. C语音的块级作用域示例如下: ,two = ; if(one < two){ ; t ...
- Gulp browserify livereload
Gulp browserify livereload 之前在browserify那个博文中介绍了gulp + browserify 不过那个配置还不能满足日常需要 搬运 https://github. ...
- 查看ORACLE 数据库及表信息
-- 查看ORACLE 数据库中本用户下的所有表 SELECT table_name FROM user_tables; -- 查看ORACLE 数据库中所有用户下的所有表 select user,t ...
- DDR、DDR2、DDR3产品区别
DDR采用一个周期来回传递一次数据,因此传输在同时间加倍,因此就像工作在两倍的工作频率一样.为了直观,以等效的方式命名,因此命名为DDR 200 266 333 400. DDR2尽管工作频率没有变化 ...
- CURD 例子
public function modify(){ $id=$_GET['id']; $m=M('user'); $arr=$m->find($id); //var_dump($arr); $t ...
- cocos2dx CCLayerColor和CCLayerColor
在cocos2dx中,默认的CCLayer背景是黑色的,有些时候需要特殊的Layer,所以cocos2dx中提供了这两种Layer CCLayerColor是可以改变背景色的Layer,示例如下: C ...
- gallery 从最左边开始显示并且默认选中第一个
import android.content.Context; import android.graphics.Camera; import android.graphics.Matrix; impo ...
- 解决android加载图片时内存溢出问题
尽量不要使用setImageBitmap或setImageResource或BitmapFactory.decodeResource来设置一张大图,因为这些函数在完成decode后,最终都是通过jav ...
- C/C++指针的指针(**p)和指针的引用(*&)使用案例分析
#include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <stdlib.h> ...