예제 #1
0
    bool sendMain(string server)
    {
        try
        {
            SmtpConfig config = new SmtpConfig(server, 25);
            SmtpBody   b      = new SmtpBody(new MailAddress(this.From),
                                             new MailAddress(new MailAddress(this.DestMailUser.MailAddress).Address, DestMailUser.FullName),
                                             this.Subject, this.Body);

            string bodyHtml = this.BodyHtml;
            if (Str.IsEmptyStr(bodyHtml) == false)
            {
                b.BodyHtml = bodyHtml;

                foreach (MailUtilResourceFile f in this.ResourceFiles)
                {
                    b.AddLinkedResourceFile(f.Data, f.Type, f.Id);
                }
            }

            foreach (MailUtilAttachedFile f in this.AttachedFiles)
            {
                b.AddAttachedFile(f.Data, f.Type, f.Filename, null);
            }

            b.Send(config);

            return(true);
        }
        catch
        {
            return(false);
        }
    }
예제 #2
0
    public static async Task <bool> SendAsync(SmtpConfig config, MailAddress from, MailAddress to, string subject, string body, bool noException = false, CancellationToken cancel = default)
    {
        try
        {
            SmtpBody sm = new SmtpBody(from, to, subject, body);

            await sm.SendAsync(config, cancel);

            return(true);
        }
        catch (Exception ex)
        {
            if (noException == false)
            {
                throw;
            }

            ex._Debug();

            return(false);
        }
    }