技术思绪摘录旅行笔记
一开始使用自带Mail组件能正常发送邮件,直到用阿里云的专有网络的时候就出现问题,邮件不能正常发送,提示无语的“邮件发送失败”,没有其他异常信息,无从可查。最后了解到原来阿里云坑爹的专有网络自动禁用了25端口(没提示的,要自己找帮助中心),然后会提示你可以尝试申请开通25端口,事实证明是一本正经的胡说八道,以后不用申请了,因为专有网络怎么都不会给你开通的。

所以,我不用25端口了,改465了,但是.net的邮箱组件貌似利用465发不出去邮件,我也懒得去找问题了,直接换一个cdo组件来。

可以引用的COM组件列表,发现里面有一个名为Microsoft CDO For Exchange 2000 Library的COM组件,就是这个


            // 设置发送方的邮件信息,例如使用网易的smtp
            string smtpServer = txt_smtp.Text.Trim(); //SMTP服务器 smtp.163.com
            string mailFrom = txt_form.Text.Trim(); //登陆用户名 发件邮箱
            string userPassword = txt_formpass.Text.Trim();//登陆密码 网易邮箱授权码  qq邮箱独立密码
            string mailTo = txt_to.Text.Trim();//发送给谁 123@qq.com
            string mailProt = txt_prot.Text.Trim();//smtp端口 465
            string mailSubject = txt_proj.Text.Trim();//主题 标题  邮件标题
            string mailContent = txt_tocont.Text.Trim();//发送内容 随便定义
            string mailFromname = txt_fromnam.Text.Trim();//谁发送的 某某某牛逼公司
         

            try
            {
                CDO.Message oMsg = new CDO.Message();
                Configuration conf = new ConfigurationClass();
                conf.Fields[CdoConfiguration.cdoSendUsingMethod].Value = CdoSendUsing.cdoSendUsingPort;
                conf.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value = CdoProtocolsAuthentication.cdoBasic;
                conf.Fields[CdoConfiguration.cdoSMTPUseSSL].Value = true;
                conf.Fields[CdoConfiguration.cdoSMTPServer].Value = smtpServer;//必填,而且要真实可用   
                conf.Fields[CdoConfiguration.cdoSMTPServerPort].Value = mailProt;//465特有
                conf.Fields[CdoConfiguration.cdoSendEmailAddress].Value = "<" + mailFrom + ">";
                conf.Fields[CdoConfiguration.cdoSendUserName].Value = mailFrom;//真实的邮件地址   
                conf.Fields[CdoConfiguration.cdoSendPassword].Value = userPassword;   //为邮箱密码,必须真实   
                conf.Fields.Update();
                oMsg.Configuration = conf;
                oMsg.HTMLBody = mailContent;
                oMsg.Subject = mailSubject;
                oMsg.From =$"({mailFromname}){mailFrom}";
                oMsg.To = mailTo;
                oMsg.AddAttachment(AppDomain.CurrentDomain.BaseDirectory+"/Comm/附件.xlsx","","");
                oMsg.Send();
                MessageBox.Show("发送成功");
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                MessageBox.Show($"发送失败:{ex.Message}");
            }


CarsonIT 微信扫码关注公众号 策略、创意、技术

留下您的脚步

 

最近评论

查看更多>>

站点统计

总文章数:275 总分类数:18 总评论数:88 总浏览数:128.45万

精选推荐

阅读排行

友情打赏

请打开您的微信,扫一扫