如何在C#中使用其他SMTP发送邮件 [英] how to use other SMTP send email in C#

查看:111
本文介绍了如何在C#中使用其他SMTP发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码发送电子邮件,但只是成功地从gmail发送到其他电子邮件地址。

我更改了主机和端口,但失败了。我如何使用其他电子邮件发送?

I used the code below to send email, but only sucessfully sent from gmail to other email address.
I changed host and port, but failed.How can I use other email to send?

private string SendMail(string from, string fromname, string to, string subject, string body, string username, string password, string server)
    {
        
        try
        {
            MailMessage mail = new MailMessage();
            mail.From = new MailAddress(from, fromname);
            mail.To.Add(to);
            mail.Subject = subject;
            mail.Body = body;
            
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;

            smtp.Credentials = new System.Net.NetworkCredential(username, password);
            smtp.EnableSsl = true;
            smtp.Send(mail);

            return "send ok";
        }
        catch (Exception exp)
        {
            return exp.Message;
        }
    }

    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        SendMail("xxx@gmail.com", "Lucy", "xxxx@gmail.com", "text", "this is a test email", "xxx@gmail.com", "xxx", "smtp.gmail.com");  
    }





我改变了主机=smtp.sina.com.cn或smtp.sina。 com,port = 25.但是无法发送电子邮件。垃圾邮件中没有任何内容。将来,我会使用一些公司的电子邮件地址发送,所以现在我需要知道从任何电子邮件发送电子邮件的方式是什么。谢谢。

推荐答案

好的,在您的示例中,显然您正在对gmail进行身份验证(不知何故) - 所以,如果您更改了邮件主机gmail给某人/其他人,然后,你需要凭证(即一个帐户)以及其他邮件主机的其他权限,才能使用它们发送邮件。



在过去的好日子里,当几乎所有人都允许你通过他们的服务发送邮件时,事情变得容易多了 - 这些天,垃圾邮件,不是这样,
ok, in your example, obviously you're authenticating to gmail (somehow)- so, if you change your mail host from gmail to someone/something else, then, you'll need credentials (ie an account) and possibly other permissions on that other mail host, to be able to use them to send mail.

Things were a lot easier in the good-old-days, when almost anyone let you send mail through their service - these days, with spam, not so


这篇关于如何在C#中使用其他SMTP发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆