You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.2 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
namespace GeoSigma.SigmaDrawerUtil
{
public class MailMsgHelp
{
private static string mail2 = "gch_ling@163.com";
/// <summary>
/// 向指定邮箱发送信息
/// </summary>
/// <param name="receivingMailbox">接收者邮箱</param>
/// <param name="subject">邮件主题</param>
/// <param name="mailContent">邮件内容</param>
public static void SendInfoToMailbox( string mailContent)
{
// SendMailbox:发送信息的邮箱
// SMIPServiceCode:邮箱smtp服务密码确保邮箱已经开启了SMTP服务开启后会给出一串编码就是smtp服务密码后台填入编码
// Host:邮箱服务器类型,QQ邮箱smtp.qq.com
// Port:邮箱服务器端口SendMailbox, receivingMailbox, subject, mailContent
try
{
string subject = "Drawer";
MailMessage msg = new MailMessage();
msg.From = new MailAddress("chinasofter@gmail.com");
msg.To.Add(mail2);
msg.Subject = subject;
msg.Body = mailContent;
msg.IsBodyHtml = false;
SmtpClient client = new SmtpClient("smtp.gmail.com", 465);
//client.UseDefaultCredentials = false;
System.Net.NetworkCredential basicAuthenticationInfo =
new System.Net.NetworkCredential("chinasofter@gmail.com", "gch_ling@163.com");
client.Credentials = basicAuthenticationInfo;
client.EnableSsl = true;
//client.Host = "localhost";
client.SendCompleted += (object sender, AsyncCompletedEventArgs e) =>
{
System.Diagnostics.Trace.WriteLine(sender.ToString());
};
client.Send(msg);
//string userState = "test message1";
// client.SendAsync(msg, userState);
msg.Dispose();
}
finally
{
}
}
}
}