Giter Club home page Giter Club logo

simplemailsender's Introduction

SimpleMailSender

a mail sender for test, debug.

为什么有本程序? Why have this repo?

本程序能用debug方式来调试出错的原因,以及放在不同环境下,可以测试连通性。
If you wanna to know, why my mail settings are all right but the email allways send failed.
Once have this, no more confuse, no more anxious.


可以保存当前配置,或者另加载配置
settings can be saved, and loaded.

主要代码 Key Code:

SmtpClient client = new SmtpClient(HostAddress, Port)
{
    EnableSsl = EnableSsl,
    Credentials = new System.Net.NetworkCredential(ServerUserName, ServerPassword)
};
var message = new MailMessage { From = new MailAddress(ServerEmail, SenderDisplayName) };
foreach (var addr in toUserAddresss)
{
    message.To.Add(new MailAddress(addr));
}
// Attachment.Foreach(r => message.Attachments.Add(r));
if (attachments != null)
{
    foreach (var s in attachments)
    {
        Attachment data = new Attachment(s, MediaTypeNames.Application.Octet);
        data.Name = s.Substring(s.LastIndexOf("/", StringComparison.Ordinal) + 1);
        data.NameEncoding = Encoding.UTF8;
        // Add time stamp information for the file.
        ContentDisposition disposition = data.ContentDisposition;
        disposition.CreationDate = File.GetCreationTime(s);
        disposition.ModificationDate = File.GetLastWriteTime(s);
        disposition.ReadDate = File.GetLastAccessTime(s);
        // Add the file attachment to this e-mail message.
        message.Attachments.Add(data);
    }
}
//Set CC list
if (cc != null)
{
    foreach (var s in cc)
    {
        message.CC.Add(s);
    }
}
//Set Bcc List
if (bcc != null)
{
    foreach (var s in bcc)
    {
        message.Bcc.Add(s);
    }
}
ServicePointManager.ServerCertificateValidationCallback = delegate (Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; };
message.Subject = subject;
message.Body = mailBody;
message.BodyEncoding = BodyEncoding;
message.IsBodyHtml = IsHtmlBody;
client.Timeout = Timeout;
client.Send(message);

simplemailsender's People

Contributors

rickxie avatar

Forkers

jiajingyang

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.