【问题标题】:Sending text to different email server将文本发送到不同的电子邮件服务器
【发布时间】:2009-10-01 07:48:09
【问题描述】:
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();

        try
        {
            MailAddress fromAddress = new MailAddress("myname@gmail.com", "Lenin");
            smtpClient.Host = "localhost";
            //smtpClient.Host = "";
            //smtpClient.Port = 25;
            message.From = fromAddress;
            message.To.Add("myname@gmail.com");
            message.Subject = "Feedback";
            //message.CC.Add("admin1@ gmail.com");
            //message.CC.Add("admin2@ gmail.com");
           // message.Bcc.Add(new MailAddress("admin3@ gmail.com"));
           // message.Bcc.Add(new MailAddress("admin4@ gmail.com"));
            message.IsBodyHtml = false;
            message.Body = txtComments.Text;
            smtpClient.Send(message);
            MessageBox.Show("Email successfully sent.");
        }
        catch (Exception ex)
        {
            MessageBox.Show("Send Email Failed." + ex.Message);                
        }

请帮助使用 Windows 应用程序将电子邮件发送到不同的服务器 .. gmail.com/yahoo.com/inbox.com ..etc。 感谢您的帮助。

【问题讨论】:

    标签: c# .net email desktop-application


    【解决方案1】:
    SmtpClient smtpClient = new SmtpClient(host, port);
    

    【讨论】:

    • MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new smtpClient("smtp.gmail.com");用户 ID = 注册用户名;密码 = register.pass;字符串 aa = txtTo.Text; mail.From = new MailAddress(userID); mail.To.Add(aa); mail.Subject = txtsubject.Text; mail.Body = txtComments.Text; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential(userID, password); SmtpServer.Send(邮件);
    【解决方案2】:
    SmtpClient client = new SmtpClient();
    client.Credentials = new System.Net.NetworkCredential("username@gmail.com", "password");
    client.EnableSsl = true;
    client.Host = "smtp.gmail.com";
    client.Port = 465 or 587; 
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.Send(MailMessage);
    

    试试这个。

    【讨论】:

    • 谢谢。但我希望“client.Host”独立,即使用任何主机并向任何人发送电子邮件。
    • 想动态设置主机并在线发送邮件到任意邮件服务器。谢谢
    • 好吧,您可以将输入中的值分配给客户端实例的主机属性,但您还需要更改网络凭据信息,例如用户名和密码以及端口号(smtp 传出端口号)希望它有所帮助.
    猜你喜欢
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 2017-08-13
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2012-05-19
    相关资源
    最近更新 更多