将输入发送到电子邮件?WinForm C#

将输入发送到电子邮件?WinForm C#,c#,winforms,email,input,send,C#,Winforms,Email,Input,Send,我正在做一个简单的WinForm项目,我有一个文本框,用户可以输入他的名字。 当他点击一个按钮时,我希望能够将这个输入发送到一个电子邮件地址或类似的地方 这可能吗?如果是,我该怎么做 以下代码用于使用自定义SMTP客户端发送电子邮件: using System; using System.Net.Mail; class Program { static void Main(string[] args) { try

我正在做一个简单的WinForm项目,我有一个文本框,用户可以输入他的名字。 当他点击一个按钮时,我希望能够将这个输入发送到一个电子邮件地址或类似的地方


这可能吗?如果是,我该怎么做

以下代码用于使用自定义SMTP客户端发送电子邮件:

using System;
using System.Net.Mail;

    class Program
    {
        static void Main(string[] args)
        {
            try
            {

                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.customsmtp.com");

                mail.From = new MailAddress("fromEmail@fromemail.com");
                mail.To.Add("toemail@toemail.com");
                mail.Subject = "Your Subject";
                mail.Body = "Your Textbox Here!";
                SmtpServer.Send(mail);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Seems some problem!");
            }

            Console.WriteLine("Email sent successfully!");
            Console.ReadLine();
        }

    }
下面的示例使用您的gmail用户名和密码从您的gmail帐户发送电子邮件:

using System;
using System.Net;
using System.Net.Mail;

namespace GMailSample
{
    class SimpleSmtpSend
    {
        static void Main(string[] args)
        {
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);           
            client.EnableSsl = true;
            MailAddress from = new MailAddress("YourGmailUserName@gmail.com", "[ Your full name here]");           
            MailAddress to = new MailAddress("your recipient e-mail address", "Your recepient name");
            MailMessage message = new MailMessage(from, to);
            message.Body = "This is a test e-mail message sent using gmail as a relay server ";
            message.Subject = "Gmail test email with SSL and Credentials";
            NetworkCredential myCreds = new NetworkCredential("YourGmailUserName@gmail.com", "YourPassword", "");           
            client.Credentials = myCreds;
            try
            {
                client.Send(message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception is:" + ex.ToString());
            }
            Console.WriteLine("Goodbye.");
        }
    }
}

希望这有帮助

以下代码用于使用自定义SMTP客户端发送电子邮件:

using System;
using System.Net.Mail;

    class Program
    {
        static void Main(string[] args)
        {
            try
            {

                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.customsmtp.com");

                mail.From = new MailAddress("fromEmail@fromemail.com");
                mail.To.Add("toemail@toemail.com");
                mail.Subject = "Your Subject";
                mail.Body = "Your Textbox Here!";
                SmtpServer.Send(mail);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Seems some problem!");
            }

            Console.WriteLine("Email sent successfully!");
            Console.ReadLine();
        }

    }
下面的示例使用您的gmail用户名和密码从您的gmail帐户发送电子邮件:

using System;
using System.Net;
using System.Net.Mail;

namespace GMailSample
{
    class SimpleSmtpSend
    {
        static void Main(string[] args)
        {
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);           
            client.EnableSsl = true;
            MailAddress from = new MailAddress("YourGmailUserName@gmail.com", "[ Your full name here]");           
            MailAddress to = new MailAddress("your recipient e-mail address", "Your recepient name");
            MailMessage message = new MailMessage(from, to);
            message.Body = "This is a test e-mail message sent using gmail as a relay server ";
            message.Subject = "Gmail test email with SSL and Credentials";
            NetworkCredential myCreds = new NetworkCredential("YourGmailUserName@gmail.com", "YourPassword", "");           
            client.Credentials = myCreds;
            try
            {
                client.Send(message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception is:" + ex.ToString());
            }
            Console.WriteLine("Goodbye.");
        }
    }
}

希望这有帮助

你试过谷歌搜索“用.NET发送电子邮件”或“用C#发送电子邮件”之类的东西吗?关于如何使用
System.Net.Mail
的例子不计其数。你有没有在谷歌上搜索过类似“用.Net发送电子邮件”或“用C#发送电子邮件”之类的东西?关于如何使用
System.Net.Mail
,这里不乏示例。非常感谢D@Dean非常欢迎:)非常感谢!:D@Dean不客气:)