2018年1月25日

2018/1/25 posted in  码农日志 DotNet
  1. .net 发送邮件
  2. 微信小程序注册小程序 onShow 函数

.net 发送邮件

587端口

SmtpClient smtpclient = new SmtpClient();
smtpclient.Host = "smtp.qq.com";
smtpclient.Port = 587;
smtpclient.Credentials = new NetworkCredential("abc@gmail.com", "XYZ");
smtpclient.EnableSsl = true;  //主要是这段         
MailMessage objmsg = new MailMessage();
objmsg.From = new MailAddress("pra@gmail.com");
objmsg.To.Add("prakash@yahoo.com");
objmsg.Subject = "Test mail";
objmsg.Body = "test mail";           
objmsg.IsBodyHtml = true;
smtpclient.Send(objmsg);

465 要用另外一种

MailMessage mmsg = new MailMessage();
//邮件主题
mmsg.Subject = "test";
mmsg.BodyFormat = MailFormat.Html;
//邮件正文 
mmsg.Body = "邮件正文"
//正文编码
mmsg.BodyEncoding = Encoding.UTF8;
//优先级
mmsg.Priority = MailPriority.Normal;
//发件者邮箱地址
mmsg.From = "memory2030@vip.163.com"; //发件人地址;
//收件人收箱地址
string email_address = db_join.ContactEmail + "";

if (!string.IsNullOrWhiteSpace(email_address)) {
    mmsg.To = "yfj@sjune.cn;tangyue@sjune.cn;eli.liu@sjune.cn"; //收件人地址
} else {
    mmsg.To = email_address + ";yfj@sjune.cn;tangyue@sjune.cn;eli.liu@sjune.cn"; //收件人地址
}

mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "登录名"); //用户名  
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "密码"); //密码
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465"); //端口 
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); //是否ssl

System.Web.Mail.SmtpMail.SmtpServer = "smtp.vip.163.com"; //Smtp服务器

try {
    SmtpMail.Send(mmsg);
    Response.Write("发送成功");
} catch (Exception ex) {
    Response.Write("发送失败,失败原因:" + ex.Message);
}

利用COD.Message

CDO.Message objMail = new CDO.Message();
try
{
objMail.To = "接收邮件账号";
objMail.From = "发送邮件账号";
objMail.Subject = "subject";//邮件主题string strHTML = @"";
strHTML = strHTML + "这里可以填写html内容";
objMail.HTMLBody = strHTML;//邮件内容
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = 465;//设置端口
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = "smtp.qq.com";
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = "发送邮件账号";
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress"].Value = "发送邮件账号";
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = "发送邮件账号";
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = "发送邮件账号";
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = "发送邮件账号登录密码";
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"].Value = "true";//这一句指示是否使用ssl
objMail.Configuration.Fields.Update();
objMail.Send();
}
catch (Exception ex) { throw ex; }
finally { }
System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail);
objMail = null;

微信小程序注册小程序 onShow 函数

在做微信小程序的过程中发现,App 函数注册小程序的 onShow 的函数,并不像官方说的只有在 当小程序启动,或从后台进入前台显示,会触发 onShow 。 在使用过程中发现,上传图片之后、拨打号码点击取消之后都会触发,暂时只发现这两种。

文档信息

  • 版权声明:自由转载-非商用-非衍生-保持署名( 创意共享3.0许可证
  • 邮箱: ntzw.geek@gmail.com
  • 在技术的世界里,需要不断学习、不断进步。对文章内容有任何疑问或异议欢迎来信讨论!