Argentini.Halide.H3Email.Send C# (CSharp) Метод

Send() публичный статический Метод

Send an e-mail message with optional attachments.
public static Send ( String senderAddress, String senderName, String recipient, String ccList, String bccList, String subject, String body, MailFormat bodyFormat, ArrayList attachments, ArrayList attachmentNames, System.Boolean useSsl ) : String
senderAddress String From address (i.e. [email protected]).
senderName String From name (i.e. Joe).
recipient String To address(es), separated by commas.
ccList String Comma-separated list of e-mail addresses for carbon copies.
bccList String Comma-separated list of e-mail addresses for blind carbon copies.
subject String Message subject.
body String Message body.
bodyFormat MailFormat MailFormat value.
attachments System.Collections.ArrayList ArrayList object with virtual paths to files OR memory streams.
attachmentNames System.Collections.ArrayList ArrayList object with filenames for memory stream attachments.
useSsl System.Boolean Should SMTP use SSL
Результат String
        public static String Send(String senderAddress, String senderName, String recipient, String ccList, String bccList, String subject, String body, MailFormat bodyFormat, ArrayList attachments, ArrayList attachmentNames, Boolean useSsl)
        {
            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

            if (String.IsNullOrEmpty(senderName))
            {
                mail.From = new MailAddress(senderAddress);
            }

            else
            {
                mail.From = new MailAddress(senderAddress, senderName);
            }

            mail.Subject = subject;
            mail.Body = body;

            foreach (String address in recipient.Split(',')) mail.To.Add(address);

            if (!String.IsNullOrEmpty(ccList))
            {
                foreach (String address in ccList.Split(',')) mail.CC.Add(address);
            }

            if (!String.IsNullOrEmpty(bccList))
            {
                foreach (String address in bccList.Split(',')) mail.Bcc.Add(address);
            }

            String result = "SUCCESS";

            AlternateView newBody = AlternateView.CreateAlternateViewFromString(
                            body,
                            Encoding.ASCII,
                            "text/plain");

            try
            {
                mail.IsBodyHtml = (bodyFormat == MailFormat.Html ? true : false);

                if (bodyFormat == MailFormat.PlainText7Bit)
                {
                    mail.Body = null;
                    newBody.TransferEncoding = TransferEncoding.SevenBit;
                    mail.AlternateViews.Add(newBody);
                }

                if (attachments != null)
                {
                    if (attachments.Count > 0)
                    {
                        for(int x = 0; x < attachments.Count; x++)
                        {
                            System.Net.Mail.Attachment data = null;

                            if (attachments[x].GetType() == typeof(string) || attachments[x].GetType() == typeof(String))
                            {
                                data = new System.Net.Mail.Attachment(HttpContext.Current.Server.MapPath((string)attachments[x]), MediaTypeNames.Application.Octet);
                                data.ContentId = attachments[x].ToString().Substring((attachments[x].ToString().LastIndexOf("/") == 0 ? 0 : attachments[x].ToString().LastIndexOf("/") + 1));
                            }

                            else if (attachments[x].GetType() == typeof(MemoryStream) && attachmentNames.Count == attachments.Count && attachmentNames[x] != null)
                            {
                                data = new System.Net.Mail.Attachment((MemoryStream)attachments[x], (string)attachmentNames[x]);
                            }

                            if (data != null)
                            {
                                mail.Attachments.Add(data);
                            }
                        }
                    }
                }

                SmtpClient smtp = new SmtpClient();

                smtp.EnableSsl = useSsl;

                smtp.Send( mail );

                if (newBody != null)
                {
                    newBody.Dispose();
                }

                mail.Dispose();
            }

            catch (Exception err)
            {
                result = err.ToString();
            }

            return result;
        }

Same methods

H3Email::Send ( string sender, string recipient, string subject, string body, MailFormat bodyFormat ) : String
H3Email::Send ( string sender, string senderName, string recipient, string subject, string body, MailFormat bodyFormat ) : String
H3Email::Send ( string senderAddress, string senderName, string recipient, string subject, string body, MailFormat bodyFormat, ArrayList attachments ) : String
H3Email::Send ( string sender, string senderName, string recipient, string ccList, string bccList, string subject, string body, MailFormat bodyFormat ) : String