首页 新闻 会员 周边 捐助

C# SmtpClient 发送邮件报 mail from address must be same as authorization user

0
悬赏园豆:15 [已解决问题] 解决于 2017-03-04 08:55

源码:

SmtpClient client = new SmtpClient();
            client.Host = SmtpHost;
            client.EnableSsl = true;  //Error: need EHLO and AUTH first
            client.UseDefaultCredentials = true;
            client.Credentials = new System.Net.NetworkCredential(SendEmail, SendEmailPwd);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            MailMessage message = new MailMessage();
            //发件人
            MailAddress addressFrom = new MailAddress(SendEmail, SendEmail);
            message.From = addressFrom;
            
            //收件人
            paraRecipientEmails = paraRecipientEmails.Replace("", ";");
            String[] recipients = Regex.Split(paraRecipientEmails, ";", RegexOptions.IgnoreCase);
            foreach (String recipient in recipients)
            {
                MailAddress recipientEmail = new MailAddress(recipient);
                message.To.Add(recipientEmail);
            }
            //邮件标题
            message.Subject = paraSubject;
            //邮件内容
            message.Body = paraBody;
            //邮件编码
            message.BodyEncoding = System.Text.Encoding.UTF8;
            //是否为HTML格式
            message.IsBodyHtml = true;
            //至少有一个收件人
            if (message.To.Count > 0)
            {
                client.Send(message);
            }
Sam Xiao的主页 Sam Xiao | 初学一级 | 园豆:6
提问于:2016-05-04 10:36
< >
分享
最佳答案
0

SmtpHost 跟 SendEmail 的域是一致的吗,还有SmtpHost的smtp服务开启没有

再把

UseDefaultCredentials设置为 false

收获园豆:15
Yu | 专家六级 |园豆:12990 | 2016-05-04 11:03

我的smtphost进了腾讯的QQ邮箱开启了。

UseDefaultCredentials设置为 false,我刚才试了一下也不行

Sam Xiao | 园豆:6 (初学一级) | 2016-05-04 17:29

@Sam Xiao: 我这是可以的 

client.Host = "smtp.qq.com";

client.EnableSsl = true; //Error: need EHLO and AUTH first

client.UseDefaultCredentials = false;

client.Credentials = new System.Net.NetworkCredential("123456@qq.com", "发送短信后得到的一串字符");

......

Yu | 园豆:12990 (专家六级) | 2016-05-04 17:33
其他回答(1)
0

发件人必须和client里的邮箱账号一样

咸鱼.net | 园豆:216 (菜鸟二级) | 2016-05-04 14:26

是设置一样了。不行的。你不信试试

支持(0) 反对(0) Sam Xiao | 园豆:6 (初学一级) | 2016-05-04 17:29

@Sam Xiao: 信

支持(0) 反对(0) 咸鱼.net | 园豆:216 (菜鸟二级) | 2016-05-05 10:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册