Программирование - это просто
Advertisement
arrow C# arrow , C#. arrow , C#. 4. SMTP (SmtpClient)
06.02.2023 .
1:
C#
Delphi
Web-
Excel-
.
, C#. 4. SMTP (SmtpClient) E-mail
megabax   
19.04.2012 .
Delphi

, C#. 4. SMTP (SmtpClient, MailMessage).

, C# SMTP. System.Net.Mail System.Net, . , SmtpClient, NetworkCredential ( ), MailMessage - . , System.IO.

rambler.ru:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net.Mail;

using System.Net;

using System.IO;

 

namespace WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void btnSendMail_Click(object sender, EventArgs e)

        {

            //

            var client = new SmtpClient("mail.rambler.ru", 25);

 

            // NetworkCredential,

            //

            var credential = new NetworkCredential(" ", " ");

            client.Credentials = credential;

 

            // SSL ( )

            // mail.rambler.ru

            client.EnableSsl = true;

 

            //

            var message = new MailMessage("< . >", "< . >", " ","<font color=red></font>");

            message.IsBodyHtml = true;

 

            //

            message.SubjectEncoding = Encoding.UTF8;

            message.BodyEncoding = Encoding.UTF8;

 

 

            //

            try

            {

                //

                var binary = File.ReadAllBytes("c:\\1\\1.txt");

                var stream = new MemoryStream(binary);

                var attachment = new Attachment(stream, "attachment_file.txt", "text/plain");

                message.Attachments.Add(attachment);

 

                //

                client.Send(message);

            }

            catch (Exception exc)

            {

                MessageBox.Show(exc.ToString());

            }

            finally

            {

                client.Dispose();

                MessageBox.Show(" ");

            }

        }

    }

}

, (, , ) .

 

 
« .   . »
 
© 2023 Программирование - это просто
Joomla! - , GNU/GPL.
© 2005-2008 Joom.Ru - Joomla!
Design by Mamboteam.com | Powered by Mambobanner.de
  .