代码之家  ›  专栏  ›  技术社区  ›  Chris Thompson

通过互联网向开发人员发送应用程序错误和日志的最佳方式是什么?

  •  9
  • Chris Thompson  · 技术社区  · 17 年前

    SMTP客户端

    6 回复  |  直到 17 年前
        1
  •  3
  •   Charlie Martin    17 年前

    以某种方式让用户知道你的意图。向他们请求代理,向他们请求电子邮件服务器,诸如此类。

    如果有安全意识的人发现你打开了一个套接字或类似的东西,并在没有通知的情况下发送数据,他们会非常紧张。

    确实如此。

        2
  •  3
  •   Peter Gfader    17 年前

    我建议 不要发送所有内容 (对您的申请的整个审核)。

    Web服务
    好

    坏

    • 与这些东西)
    • 使用db后端创建web服务的额外开发
    • 稍后创建其他字段是不好的


    好


    • -->超文本标记语言
    • 日志格式和信息的更改很容易,因为我们使用了HTML电子邮件

    坏

    • 每个用户的特殊配置(smtp服务器、电子邮件用户等)
    • 电子邮件大小限制(5MB-8MB??)
    • 将电子邮件记录到数据库需要大量开发
        3
  •  2
  •   Ali Shafai    17 年前

    在我工作的地方,我们使用3种方法

    • 大量 配置,并与“大公司”IT部门合作,找出他们的邮件服务器是什么,以及如何对其进行身份验证并通过它发送。然后还有诺顿互联网安全等程序,可以阻止客户端机器上的出站SMTP流量,这会给工作带来额外的麻烦。
    • 提交到我们服务器上的asmx。这是我们首选的方法,但有很多事情会妨碍我们。它主要是代理,但诺顿也可以介入并击败你。如果涉及代理,请跑开:-)
    • HTTP POST使用HttpWebRequest和mime类型的多部分/形式编码。它也有代理和防火墙问题,但有时可以在asmx提交失败的情况下工作。

    祝你好运。你说得对 许多 如果你有堆栈跟踪,甚至可能有一个可怜的老用户在做什么的屏幕,那么调试就更容易了。

        4
  •  2
  •   Dan F    17 年前

    你可以自己写,也可以用类似的东西 log4net

        5
  •  0
  •   rmeden    17 年前

    我喜欢把这样的东西作为电子邮件发送到专用邮箱。这样我就可以轻松地存档、搜索或忽略它。

    在客户端/发送方方面,我认为弹出式提供发送日志是一个好主意。如果是windows,则可以使用MAPI发送电子邮件。在unix系统上,“邮件”问题适用于大多数系统。

    您可以在确认消息中提示用户输入电子邮件地址,并可能提供一些发送方式的选项(包括复制/粘贴到他们选择的邮件客户端)。

    你应该做一件事 这样做是在未经用户许可的情况下发送信息。

        6
  •  0
  •   blak3r    17 年前

    如果你不希望在一天内发送那么多报告。..您可以创建一个gmail帐户并使用它来发送电子邮件,以避免强制用户配置SMTP服务器。不确定gmail的条款和条件是什么。

    这是我写的一个类,它使用gmail帐户发送电子邮件。..

    显然,这里存在一些安全问题,比如有人可能会访问你的gmail帐户。所以,考虑到这一点。

    此类中有同步或异步发送电子邮件的方法。

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Collections;
    using System.Text;
    using System.Net;
    using System.Net.Mail;
    using System.Net.Mime; 
    //Mime is Not necerrary if you dont change the msgview and 
    //if you dont add custom/extra headers 
    using System.Threading;
    using System.IO;
    using System.Windows.Forms; // needed for MessageBox only.
    
    
    
    namespace BR.Util
    {
        public class Gmailer
        {
    
            SmtpClient client = new SmtpClient();
            static String mDefaultToAddress = "yourToAddress@yourdomain.com";
            static String mDefaultFromAddress = "anonymous@gmail.com";
            static String mDefaultFromDisplayName = "Anonymous";
    
            String mGmailLogin = "someaccount@gmail.com";
            String mGmailPassword = "yourpassword";
    
    
            public Gmailer()
            {
                client.Credentials = new System.Net.NetworkCredential(mGmailLogin, mGmailPassword);
                client.Port = 587;           
                client.Host = "smtp.gmail.com";
                client.EnableSsl = true;
                client.SendCompleted += new SendCompletedEventHandler(Gmailer_DefaultAsyncSendCompletedHandler);
            }
    
            public void setSendCompletedHandler(SendCompletedEventHandler pHandler)
            {
                client.SendCompleted -= Gmailer_DefaultAsyncSendCompletedHandler;
                client.SendCompleted += pHandler;
            }
    
            /// <summary>
            /// Static method which sends an email synchronously.
            /// It uses a hardcoded from email.
            /// </summary>
            /// <returns></returns>
            public static bool quickSend(String toEmailAddress, String subject, String body)
            {
                return Gmailer.quickSend(toEmailAddress, mDefaultFromAddress, mDefaultFromDisplayName, subject, body);
            }
    
            /// <summary>
            /// Static method which sends an email synchronously.
            /// It uses the hardcoded email address.
            /// </summary>
            /// <returns>true if successful, false if an error occurred.</returns>
            public static bool quickSend(String toEmailAddress, String fromEmailAddress,
                                         String fromDisplayName, String subject, String body)
            {
                try
                {
                    Gmailer gmailer = new Gmailer();
                    System.Net.Mail.MailMessage mailMsg = gmailer.createMailMessage(toEmailAddress, fromEmailAddress, fromDisplayName, subject, body);
                    gmailer.send(mailMsg);
                }
                catch (Exception ex)
                {
                    return false;
                }
                return true;
            }
    
            // <summary> creates a MailMessage object initialized with the default values.</summary>
            public System.Net.Mail.MailMessage createMailMessage()
            {
                return createMailMessage(mDefaultToAddress, mDefaultFromAddress, mDefaultFromDisplayName, mDefaultEmailSubject, mDefaultEmailBody);
            }
    
            public System.Net.Mail.MailMessage createMailMessage(String toEmailAddress, String fromEmailAddress, 
                                                                 String fromDisplayName, String subject, String body)
            {
                //Build The MSG
                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                msg.To.Add(toEmailAddress);
                msg.From = new MailAddress(fromEmailAddress, fromDisplayName, System.Text.Encoding.UTF8);
                msg.Subject = subject;
                msg.SubjectEncoding = System.Text.Encoding.UTF8;
                msg.Body = body;
                msg.BodyEncoding = System.Text.Encoding.UTF8;
                msg.IsBodyHtml = false;
                msg.Priority = MailPriority.High;
                return msg;
            }
    
            public System.Net.Mail.MailMessage addAttachmentToMailMessage(System.Net.Mail.MailMessage msg, String attachmentPath)
            {
                msg.Attachments.Add(new Attachment(attachmentPath));
                return msg;
            }
    
            // <summary> method which blocks until the MailMessage has been sent.  Throws
            // System.Net.Mail.SmtpException if error occurs.</summary>
            public void send(System.Net.Mail.MailMessage pMailMessage)
            {
                //try {
                    client.Send(pMailMessage);
                //}
                //catch (System.Net.Mail.SmtpException ex)
                //{
                //    MessageBox.Show(ex.Message, "Send Mail Error");
                //}
            }
    
            // 
            public void sendAsync(System.Net.Mail.MailMessage pMailMessage)
            {
                object userState = pMailMessage;
                try
                {
                    MailSent = false;
                    client.SendAsync(pMailMessage, userState);
                }
                catch (System.Net.Mail.SmtpException ex)
                {
                    MessageBox.Show(ex.Message, "Send Mail Error");
                }
            }
    
            // <summary> 
            // Provides a default SendComplete handler which is activated when an AsyncCompletedEvent 
            // is triggered by the private client variable.  This is useful for debugging etc.
            // Use the method setSendCompletedHandler to define your own application specific handler.
            // That method also turns this handler off.
            // </summary>
            public void Gmailer_DefaultAsyncSendCompletedHandler(object sender, AsyncCompletedEventArgs e)
            {
                MailMessage mail = (MailMessage)e.UserState;
                string subject = mail.Subject;
    
                if (e.Cancelled)
                {
                    string cancelled = string.Format("[{0}] Send canceled.", subject);
                    MessageBox.Show(cancelled);                
                }
                if (e.Error != null)
                {
                    string error = String.Format("[{0}] {1}", subject, e.Error.ToString());
                    MessageBox.Show(error);                
                }
                else
                {
                    MessageBox.Show("Message sent.");
                }
                MailSent = true;
            }
    
    
            private bool _MailSent = false;
            /// <summary>
            /// Set to false when an async send operation is started and is set to true when finished.
            /// </summary>
            public bool MailSent
            {
                set
                {
                    _MailSent = value;
                }
                get
                {
                    return _MailSent;
                }
            }
        }
    }