简体   繁体   English

从C#发送邮件故障转移代理

[英]Sending mail from c# fails over proxy

The following is my code to send a mail over a http proxy. 以下是我的通过http代理发送邮件的代码。 I have set my proxy to the same as mentioned. 我已将代理设置为与上述相同。 Now when I try to run the program, after some time it says *System.Net.WebException: The remote name could not be resolved. 现在,当我尝试运行该程序时,过了一会儿它显示* System.Net.WebException:无法解析远程名称。 May I know where I am going wrong? 我可以知道我要去哪里了吗?

protected void mailto(string message)
    {
        WebRequest.DefaultWebProxy = new WebProxy("10.1.1.4", 8080);
        try
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            mail.From = new MailAddress("mymail@gmail.com");
            mail.To.Add("to_address");
            mail.Subject = "For Data Using";
            mail.Body = message;
            SmtpServer.Port = 465;// Tried even with 587, but no luck
            SmtpServer.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "mypassword");
            SmtpServer.EnableSsl = true;
            SmtpServer.Send(mail);
            Debug.WriteLine(Environment.NewLine + "message sent");
        }
        catch (Exception ex)
        {
            Debug.WriteLine("Message not sent" + ex.ToString());
        }
    }

I have faced same issue with sending a mail from c# using Gmail SMTP, the problem was the Port. 使用Gmail SMTP从c#发送邮件时,我遇到了同样的问题,问题是端口。 Try to use the port : 587 尝试使用端口:587

            SmtpServer.Port = 587;

Also don't forget to Enable POP & IMAP Access to your Gmail account, go to settings , choose 'Forwarding and POP/IMAP' from the tabs and enable the POP & IMAP 同样不要忘记为您的Gmail帐户启用POP&IMAP访问,进入设置,从标签中选择“转发和POP / IMAP”,然后启用POP&IMAP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM