C# E-mail Client Mails Not Received

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cnixuser
    New Member
    • Dec 2006
    • 80

    C# E-mail Client Mails Not Received

    Hi, I am trying to write an application that will e-mail sales data reports once per day. I have largely succeeded in creating the application and I am able to e-mail my reports to some e-mail addresses such as gmail ones ;however, when attempting to send e-mails to addresses on my companies internal server the e-mails never arrive. I was wondering if anyone knew what could allow gmail addresses to receive e-mails from my application, but not allow other servers to receive mail from my application, below is the portion of code doing the e-mailing:

    Code:
            public string SendEmail()
            {
                try
                {
                    using (System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(EmailFrom, EmailTo))
                    {
                        message.Subject = ConfigurationManager.AppSettings["emailSubject"].ToString();
                        message.Body = ConfigurationManager.AppSettings["emailMainBody"].ToString() + "\n\nSent On:\n" + DateTime.Now.ToString() + "\n" + SerialPortCommands.RemoveControlCharacterPairs(SerialPortCommands.Asciireport);
                        //System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient("localhost");
                        System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient("127.0.0.1");
                        Client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis;
                        Client.Send(message);
                        Thread.Sleep(2000);
                    }
                    return null;
                }
                catch (Exception ex)
                {
                    Log.WriteToLog(ex);
                    return "Error Code: email-1";
                    Application.Restart();
                }
            }
    And here are the relevant portions from my App.Config file:

    Code:
    <add key="ToAddress" value="AddressSendingTo@gmail.com"/>
        <add key="FromAddress" value="test@foo.com"/>
        <add key="emailSubject" value="==DEX Collector Message== Your Dex Report Has Been Sent"/>
        <add key="emailMainBody" value="Vending Machine DEX Data"/>
        <add key="MessageSendTime" value="1:17:00 PM"/>
    any help would be greatly appreciated, as I am quite stumped :)
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Are you sure that your emails aren't going to your junk mail boxes? I almost drove myself crazy that way once

    Comment

    • cnixuser
      New Member
      • Dec 2006
      • 80

      #3
      Originally posted by insertAlias
      Are you sure that your emails aren't going to your junk mail boxes? I almost drove myself crazy that way once
      When I check my company e-mail address, I find no e-mail in the junk mail box. When I send to my gmail account, the e-mail always goes through with no problem.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        I would check the logs on the company email server, they may be getting rejected before even making it to client's emails.
        Are you sending the emails from a valid email account? Have you checked THAT accounts email box? There might be like "destinatio n unreachable" or something emails in there that might better describe it.

        Comment

        • cnixuser
          New Member
          • Dec 2006
          • 80

          #5
          Originally posted by Plater
          I would check the logs on the company email server, they may be getting rejected before even making it to client's emails.
          Are you sending the emails from a valid email account? Have you checked THAT accounts email box? There might be like "destinatio n unreachable" or something emails in there that might better describe it.
          Well, I'm not actually sending from an e-mail account that I have set up. For example I can use a purely non-existent dummy address "test@foo.c om", to get the reports sent to gmail.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Originally posted by cnixuser
            Well, I'm not actually sending from an e-mail account that I have set up. For example I can use a purely non-existent dummy address "test@foo.c om", to get the reports sent to gmail.
            Hmm, try sending from a valid email account and see if your company's server lets the emails go through?

            Comment

            • cnixuser
              New Member
              • Dec 2006
              • 80

              #7
              Originally posted by Plater
              Hmm, try sending from a valid email account and see if your company's server lets the emails go through?
              I have tried that from my development pc here at work, which does have an e-mail account set up with the company and it works ;however, this won't be doable for the pc's that are going to be hosting the application out in the field. I did consult IT, and found out that our e-mail accounts are actually handled by godaddy.com, would this have any impact on changes that I might have to make to my code?
              Last edited by cnixuser; Aug 12 '08, 04:14 PM. Reason: grammar

              Comment

              • Curtis Rutland
                Recognized Expert Specialist
                • Apr 2008
                • 3264

                #8
                I think that it just has to come from a real valid email address. It can be the same one, but they have to be real.

                That's one of those things that are determined by the server.

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  Yes, just make a dummy account on the email server for it. We use one that's ReportServer@ou rdomain.com that sounds out reports

                  Comment

                  • cnixuser
                    New Member
                    • Dec 2006
                    • 80

                    #10
                    Originally posted by Plater
                    Yes, just make a dummy account on the email server for it. We use one that's ReportServer@ou rdomain.com that sounds out reports
                    Do you used SmtpClient.Cred entials = new NetworkCredenti al("username"," password"); anywhere in your code, with the object reference to the SmtpClient used instead of directly here of course :)
                    Last edited by cnixuser; Aug 12 '08, 04:40 PM. Reason: I know about objects

                    Comment

                    • Plater
                      Recognized Expert Expert
                      • Apr 2007
                      • 7872

                      #11
                      Well technically no, because I built my own SMTPClient as I disliked the built in one.
                      But yes, I *DO* send the authentication information to the mail server, my mail server won't send emails out unless you are a valid user.

                      Comment

                      • cnixuser
                        New Member
                        • Dec 2006
                        • 80

                        #12
                        Originally posted by Plater
                        Well technically no, because I built my own SMTPClient as I disliked the built in one.
                        But yes, I *DO* send the authentication information to the mail server, my mail server won't send emails out unless you are a valid user.
                        Have you had success sending to e-mail accounts hosted on goDaddy servers?

                        Comment

                        • Plater
                          Recognized Expert Expert
                          • Apr 2007
                          • 7872

                          #13
                          Originally posted by cnixuser
                          Have you had success sending to e-mail accounts hosted on goDaddy servers?
                          I have not had any failures that I have seen.

                          Comment

                          • cnixuser
                            New Member
                            • Dec 2006
                            • 80

                            #14
                            Originally posted by Plater
                            I have not had any failures that I have seen.
                            I just can't figure out what it could be. I am able to send to gmail just fine without using credentials.

                            Comment

                            • Plater
                              Recognized Expert Expert
                              • Apr 2007
                              • 7872

                              #15
                              Originally posted by cnixuser
                              I just can't figure out what it could be. I am able to send to gmail just fine without using credentials.
                              And I we all keep telling you that you need to use credentials.
                              There really shouldn't be anything difficult to grasp on this concept.
                              Have you even tried to use valid credentials?

                              Comment

                              Working...