/// <summary>
/// 发送邮件
/// </summary>
/// <returns></returns>
public static bool SendEmail(string subject, string body, string to)
{
MailMessage myEmail = new MailMessage();
Encoding eEncod = Encoding.GetEncoding("utf-8");
myEmail.From = new System.Net.Mail.MailAddress(SmtpUserName, SmtpUserName, eEncod);
myEmail.To.Add(to);
myEmail.Subject = subject;
myEmail.Body = body;
myEmail.BodyEncoding = Encoding.UTF8;
myEmail.Priority = System.Net.Mail.MailPriority.Normal;
myEmail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient(SmtpServer, 587);
smtp.EnableSsl = true;
string UserName = SmtpUserName;
string Password = SmtpPassword;
smtp.Credentials = new System.Net.NetworkCredential(UserName, Password);
try
{
smtp.Send(myEmail);
return true;
}
catch (Exception ex)
{
return false;
}
return true;
}

注意:

使用gmail发送邮件写端口,但是当把端口设为465时,会报超时,所以只能设为587

使用Gmail发送邮件心得的更多相关文章

  1. Thinkphp 使用gmail发送邮件

    1.Thinkphp 发送邮件内容来自:http://www.thinkphp.cn/code/32.html /** * 系统邮件发送函数 * @param string $to 接收邮件者邮箱 * ...

  2. python发送邮件心得体会

    利用本地smtp server发送 windows下尝试装了两个smtp server大概配置了下,发现没法生效,也没时间仔细研究了.装上foxmail发现以前可以本地发送的选项已经无法找到. 不带附 ...

  3. 使用php+gmail 发送邮件

    <?php namespace app\index\controller; use think\Controller; use PHPMailer\PHPMailer; class Test e ...

  4. SpringBoot 2.x 集成QQ邮箱、网易系邮箱、Gmail邮箱发送邮件

    在Spring中提供了非常好用的 JavaMailSender接口实现邮件发送,在SpringBoot的Starter模块中也为此提供了自动化配置. 项目源码已托管在Gitee-SpringBoot_ ...

  5. phpmailer 发送邮件(一)

    phpmailer下载地址: PHPMailer : https://github.com/PHPMailer/PHPMailer 一.基本要求 Web访问正常(apache可以正常访问) php 设 ...

  6. PHPMailer发送邮件(一)

    Github 地址:(已更新,适用于旧版) PHPMailer : https://github.com/PHPMailer/PHPMailer 一.基本要求 Web访问正常(apache可以正常访问 ...

  7. C#邮件发送问题(一)

    邮件发送需考虑很多因素,包括发送邮件客户端(一般编码实现),发送和接收邮件服务器设置等.如果使用第三方邮件服务器作为发送服务器,就需要考虑该服务器的发送限制,(如发送邮件时间间隔,单位时间内发送邮件数 ...

  8. Android实现电子邮箱客户端

    本文主要讲述了安卓平台上利用QQ邮箱SMTP协议,POP3协议发送与接收消息的实现 发送邮件核心代码 import java.security.Security; import java.util.D ...

  9. backtrack5渗透 笔记

    目录        1.信息收集        2.扫描工具        3.漏洞发现        4.社会工程学工具        5.运用层攻击msf        6.局域网攻击       ...

随机推荐

  1. 基本的TCP编程

    int socket(int family,int type,int protocol); family: AF_INET ipv4协议 AF_INET6 ipv6协议 AF_LOCAL unix域协 ...

  2. 窥探EasyMock(2)进阶使用篇

    from:http://www.iteye.com/topic/310313 1. 生成 Mock 对象 如何创建一个需要严格遵守调用顺序的mock对象? SomeInterface mockObj  ...

  3. mysql修改用户密码 新增用户

    修改密码: mysql> grant all privileges on *.* to yongfu_b@'192.168.1.%' identified by 'my_password_new ...

  4. CMSIS Example - osTimer osTimerCreate osTimerStart

    osTimerId timer; uint32_t cnt=; void timerHandler( void * arg ) { cnt++; osTimerStart( timer, ); } o ...

  5. UVa11205 The Broken Pedometer

    // 题意:有P个LED灯,以及N个字符,要求选出个数最少的LED灯,使得即使只有这些灯正常工作,也能区分出这N个字符 // 题意抽象:输入两个整数P, N以及N行P列的01矩阵,找少的列,能区分所有 ...

  6. 推荐大家使用的CSS书写规范及顺序

    @设计达人网 写了这么久的CSS,但大部分前端er都没有按照良好的CSS书写规范来写CSS代码,这样会影响代码的阅读体验,这里我总结一个CSS书写规范.CSS书写顺序供大家参考,这些是参考了国外一些文 ...

  7. 58 web框架Argo代码分析

    贴地址:https://github.com/58code/Argo 核心jar javax.servlet-api 3.0.1 guice 3.0 velocity 1.7 框架使用 servlet ...

  8. Codeforces Educational Codeforces Round 3 A. USB Flash Drives 水题

    A. USB Flash Drives 题目连接: http://www.codeforces.com/contest/609/problem/A Description Sean is trying ...

  9. cdoj 03 BiliBili, ACFun… And More! 水题

    Article Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/3 Descr ...

  10. Nazo解密游戏攻略

    啊,终于腾出时间来玩这个游戏了,顺手写一下攻略吧…… 第0关:http://cafebabe.cc/nazo/ 第一关:第一关很简单 点一下就好了 http://cafebabe.cc/nazo/le ...