C#发送邮件DEMO
虽然网上有很多类似的DEMO,但是还是整个封装好的例子,以便以后用;
发送邮箱是直接在web.config配置的。
protected void Button1_Click(object sender, EventArgs e) {
string mailto = "843935025@qq.com";
string mailSubject = "C#邮件测试";
string mailBody = "C#邮件测试成功";
string mailFrom = ConfigurationManager.AppSettings["FromMail"];
if (MySendMail(mailto, mailSubject, mailBody, mailFrom)) {
Error.Text="发送成功!";
}
else {
Error.Text = "发送失败!";
}
}
public bool MySendMail(string mailto, string mailsubject, string mailbody, string mailFrom) {
try {
System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress(mailFrom);//邮件发送人地址
System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress(mailto);//收件人地址
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);//邮件对象
message.Subject = mailsubject;
message.Body = mailbody;
System.Net.Mail.SmtpClient mySmth = new System.Net.Mail.SmtpClient();//设置服务器
mySmth.Send(message);//发送邮件
message.Dispose();
return true;
}
catch { return false; }
}
web.config
<appSettings>
<add key="FromMail" value="wust_chenlei@163.com"/>
</appSettings>
<system.net>
<mailSettings>
<smtp from="Emailname">
<network host="smtp.163.com" userName="wust_chenlei@163.com" password="cl19911111" port="25" defaultCredentials="false"/>
</smtp>
</mailSettings>
</system.net>
C#发送邮件DEMO的更多相关文章
- javamail 发送邮件demo
package com.suntray.test; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.M ...
- smtp自动发送邮件demo
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- javamail 发送邮件demo(文字与附件)
package com.get.one; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.Multip ...
- Java发送邮件Demo
就是个Demo,有使用Spring的东西 package xxxxxxx.common.utils; import org.springframework.mail.javamail.JavaMail ...
- .net System.Net.Mail 之用SmtpClient发送邮件 Demo
private static bool sendMail() { try { //接收人邮箱 string SendTo = "XXXXX@163.com"; //抄送人邮箱 st ...
- node 发送邮件demo (QQ邮箱)
nodemailer是nodejs中的邮件发送模块,本文使用的版本为2.5.0 --下载模块 npm install nodemailer npm下载模块后,在项目中引入就可以使用: var node ...
- .net System.Net.Mail 之用SmtpClient发送邮件Demo
private static bool sendMail() { try { //接收人邮箱 string SendTo = "XXXXX@163.com ...
- JavaMail发送邮件的笔记及Demo
最近碰到一个需求,就是注册用户时候需要向用户发送激活邮箱,于是照着网上搜来的demo自己试着运行了一下,发件时我用的是网易163邮箱,收件时用QQ邮箱,运行后报了一个错误: 网络上搜索解决方式,多次尝 ...
- PHPMailer 使用方法(支持群发):
一.下载函数包 地址:https://github.com/PHPMailer/PHPMailer 二.测试服务器环境 通过phpinfo()函数打印出是否支持Sockets(Socket属于php的 ...
随机推荐
- 编译bash实现history的syslog日志记录
摘要: 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://koumm.blog.51cto.com/703525/1763145 一 ...
- 荣耀A55高调上市仅仅为孤独求败?
坦白说.华为近年来在手机市场上确实取得了一些成绩.比方之前P6的出现就凭借超薄的设计.突出的性价比让大家看到了国产手机的新希望.按理说.在手机市场上尝到甜头的华为应该继续坚持低价.亲民的路线, ...
- CheckBox:屏蔽setChecked方法对OnCheckedChangeListener的影响
对于CheckBox的OnCheckedChangeListener,有两种情况下会被触发: (1)用户点击了一下CheckBox: (2)代码中调用了setChecked(boolean check ...
- 将IP表存入SQL里的程序
将IP表存入SQL里的程序 写得比較粗糙,另一点错误,只是能达到效果.请大家測试 create.asp ---------------------------------------------- ...
- java内部类的初始化
public class InnerClassTest { /** * @param args */ public static void main(String[] args) { // TODO ...
- BZOJ 3544 treap (set)
我只是想找个treap的练习题-- 每回找到lower_bound 就好啦 //By SiriusRen #include <cstdio> #include <cstring> ...
- 分享js中 pageY = clientY + document.body.scrollTop 之间的关系
//这里没有考虑兼容ie模式下 兼容一般主流浏览器 var $1 = document.getElementById('main') $1.onclick = function(e){ console ...
- Codefroces 849 A,B
A. Odds and Ends time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- JSP中 input type 用法
JSP中 input type 用法 Input表示Form表单中的一种输入对象,其又随Type类型的不同而分文本输入框,密码输入框,单选/复选框,提交/重置按钮等,下面一一介绍. 1,type=te ...
- Swift学习笔记(7)--控制流
1.For循环 //1.条件递增 for var index = 0; index < 3; ++index { println("index is \(index)") } ...