SMTP电子邮件 [英] SMTP E-mail

查看:401
本文介绍了SMTP电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个小程序,该程序生成PDF并将其通过电子邮件发送给目标用户,并使用"localhost"作为smtp服务器.这适用于我的本地计算机.但是,当我将程序移至服务器时,永远不会收到电子邮件.如果我更改程序并使用邮件主机的IP,它将正常工作.问题在于电子邮件将移至外部来源.因此,将不再有内部电子邮件服务器.这是简单的代码,以防万一有人有任何疑问. XXX是IP地址所在的位置.

任何人都有任何想法

I have created a small program that generates a PDF and e-mails it to the intended user, using the "localhost" as the smtp server. This works on my local machine. However when I move the program to a server the e-mail are never recieved. If I alter the program and use the ip of the mail host it will work. The problem is that the e-mail will be moving to an outside source. So there will no longer be and internal e-mail server. Here is the code simple just in case anyone has any questions. XXX are where the IP address would be.

Anyone have any ideas

private void SendMailWithAttachment(string strFrom, string strTo, string strSubject, string strBody, Attachment attOrder, Attachment attPacking)
        {
            try
            {
                MailMessage mail = new MailMessage(strFrom, strTo, strSubject, strBody);
                mail.Attachments.Add(attOrder);
                mail.Attachments.Add(attPacking);
                SmtpClient smtp = new SmtpClient("xxx.xxx.xxx.xxx");
                smtp.Send(mail);
                mail.Dispose();
            }
            catch(Exception ex)
            {
                string strError = ex.Message;
                //txtBigText.Visible = true;
                //txtBigText.Text = "Mail w/ Attachment Not Sent";
            }
        }

推荐答案

第一个猜测:检查防火墙设置.你能做到吗?

谢谢.
--SA
First guess: check up firewall settings. Could you do that?

Thank you.
--SA


是否需要通过主机SMTP进行身份验证?请参阅 SmtpClient.Credentials [
Do you need to be authenticated to the host SMTP? see SmtpClient.Credentials[^]


您需要根据要部署的应用程序类型将主机名/IP地址移动到app.config或web.config文件.这样,您可以在部署时配置应用程序,而无需重建程序集.
You need to move the hostname/IP Address to either the app.config or web.config file depending on the type of application you are deploying. That way you can configure the application on deployment without having to rebuild the assemblies.


这篇关于SMTP电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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