Sending emails via c# code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe_Black

    Sending emails via c# code

    Hi all,

    I have googled this and found some answers but none that give me exactly
    what I'm after, maybe someone here can help.

    I have an app that will be distributed to users for their laptop and
    home PC's, I have no idea what operating system they are using although
    it will be at least Win 98, I also have no idea what mail client they
    will be using or which ISP their mail account is with. I would like to
    send an email from the app using their default mail account, I had a
    look at the System.Web.Mail classes, specifically MailMessage class, but
    this requires a mail server, how would I get this information from the
    system? also it requires a mail from field which I would like to get
    from the system without asking the user to enter it, again how is this
    achieved?

    Is there another way to do what I want to do, I know that there are the
    Indy components but I'd rather avoid having to distibute more Dll's,
    unless the Indy route is the best.

    The only thing I can guarantee is that the target machine that this app
    is installed on will have a mail account.

    Many thanks

    Joe
  • Adam Barker

    #2
    Re: Sending emails via c# code

    I would build the SMTP server property as configurable in your application.

    Try and standardise the from address if possible - maybe use the machine
    name or currently login name.

    "Joe_Black" <JoeBlack@newsg roups.nospam> wrote in message
    news:%23RGThbcZ FHA.228@TK2MSFT NGP12.phx.gbl.. .[color=blue]
    > Hi all,
    >
    > I have googled this and found some answers but none that give me exactly
    > what I'm after, maybe someone here can help.
    >
    > I have an app that will be distributed to users for their laptop and home
    > PC's, I have no idea what operating system they are using although it will
    > be at least Win 98, I also have no idea what mail client they will be
    > using or which ISP their mail account is with. I would like to send an
    > email from the app using their default mail account, I had a look at the
    > System.Web.Mail classes, specifically MailMessage class, but this requires
    > a mail server, how would I get this information from the system? also it
    > requires a mail from field which I would like to get from the system
    > without asking the user to enter it, again how is this achieved?
    >
    > Is there another way to do what I want to do, I know that there are the
    > Indy components but I'd rather avoid having to distibute more Dll's,
    > unless the Indy route is the best.
    >
    > The only thing I can guarantee is that the target machine that this app is
    > installed on will have a mail account.
    >
    > Many thanks
    >
    > Joe[/color]


    Comment

    • Joe_Black

      #3
      Re: Sending emails via c# code

      Adam Barker wrote:[color=blue]
      > I would build the SMTP server property as configurable in your application.
      >
      >
      > "Joe_Black" <JoeBlack@newsg roups.nospam> wrote in message
      > news:%23RGThbcZ FHA.228@TK2MSFT NGP12.phx.gbl.. .
      >[/color]

      Hi Adam,

      Hmmm, I'd like to think the users would have the abilty to do enter the
      smtp server details :-), however our target audience wont really be that
      computer literate. Also the only time the email part of the app will be
      needed is when they register their software, so ideally I'd like it to
      be a simple case of click and go for them.
      [color=blue]
      > Try and standardise the from address if possible - maybe use the
      >machine name or currently login name.[/color]

      Does this mean that the from address does not have to be a valid email
      address? i.e.

      Their actual email is
      someone@ansmtps erver.com

      but the from address in the MailMessage object could be set to
      registration@ad omain.com

      Many thanks
      Joe

      Comment

      • Adam Barker

        #4
        Re: Sending emails via c# code

        I can't see how you could cope with all the different configurations without
        programmaticall y checking properties of an Outlook profile for example. Even
        this relies on the user using Outlook.

        You could make the app ask for the server after first installing and then
        never bother the user again. Then you just need to let the user know the
        details required, i.e. their SMTP server. (If you know their IP, you could
        look this up in advance to help them)

        The 'from' address is your choice to a certain extent. Admittedly I've only
        used a custom address when I've been in control of the SMTP server itself
        and can enable relaying etc.

        "Joe_Black" <JoeBlack@newsg roups.nospam> wrote in message
        news:%23J3JPCdZ FHA.2796@TK2MSF TNGP10.phx.gbl. ..[color=blue]
        > Adam Barker wrote:[color=green]
        >> I would build the SMTP server property as configurable in your
        >> application.
        >>
        >>
        >> "Joe_Black" <JoeBlack@newsg roups.nospam> wrote in message
        >> news:%23RGThbcZ FHA.228@TK2MSFT NGP12.phx.gbl.. .
        >>[/color]
        >
        > Hi Adam,
        >
        > Hmmm, I'd like to think the users would have the abilty to do enter the
        > smtp server details :-), however our target audience wont really be that
        > computer literate. Also the only time the email part of the app will be
        > needed is when they register their software, so ideally I'd like it to be
        > a simple case of click and go for them.
        >[color=green]
        > > Try and standardise the from address if possible - maybe use the machine
        > > name or currently login name.[/color]
        >
        > Does this mean that the from address does not have to be a valid email
        > address? i.e.
        >
        > Their actual email is
        > someone@ansmtps erver.com
        >
        > but the from address in the MailMessage object could be set to
        > registration@ad omain.com
        >
        > Many thanks
        > Joe[/color]


        Comment

        • Joe_Black

          #5
          Re: Sending emails via c# code

          Adam Barker wrote:[color=blue]
          > I can't see how you could cope with all the different configurations without
          > programmaticall y checking properties of an Outlook profile for example. Even
          > this relies on the user using Outlook.
          >
          > You could make the app ask for the server after first installing and then
          > never bother the user again. Then you just need to let the user know the
          > details required, i.e. their SMTP server. (If you know their IP, you could
          > look this up in advance to help them)
          >
          > The 'from' address is your choice to a certain extent. Admittedly I've only
          > used a custom address when I've been in control of the SMTP server itself
          > and can enable relaying etc.
          >
          > "Joe_Black" <JoeBlack@newsg roups.nospam> wrote in message
          > news:%23J3JPCdZ FHA.2796@TK2MSF TNGP10.phx.gbl. ..
          >[/color]

          I see the problem, what about this then:

          Can I find the default mail account, and tell it to create an email with
          my email address, subject and body in it. This would negate the need to
          know any settings for SMTP etc. but would rely instead on an external
          app, like outlook express for instance. This would also mean if the user
          had a hotmail account that does not use SMTP my app could still send the
          email, although the user themselveswould have to click "Send".

          Thanks

          Joe

          Comment

          • Adam Barker

            #6
            Re: Sending emails via c# code

            I would've said it was far easier to use MailMessage than to start checking
            for mail profiles. Outlook these days is quite locked down security wise so
            I'm not sure how automatic you could make this. I would almost definitely go
            for prompting for the smtp server.

            Depending on the context on which you're developing this app, could you not
            use your own SMTP server and therefore hardcode this address in your app?
            This way a) you wouldn't need to worry about the user knowing any mail
            information, and b) you could enable relaying.

            "Joe_Black" <JoeBlack@newsg roups.nospam> wrote in message
            news:uFPTRMdZFH A.3280@TK2MSFTN GP09.phx.gbl...[color=blue]
            > Adam Barker wrote:[color=green]
            >> I can't see how you could cope with all the different configurations
            >> without programmaticall y checking properties of an Outlook profile for
            >> example. Even this relies on the user using Outlook.
            >>
            >> You could make the app ask for the server after first installing and then
            >> never bother the user again. Then you just need to let the user know the
            >> details required, i.e. their SMTP server. (If you know their IP, you
            >> could look this up in advance to help them)
            >>
            >> The 'from' address is your choice to a certain extent. Admittedly I've
            >> only used a custom address when I've been in control of the SMTP server
            >> itself and can enable relaying etc.
            >>
            >> "Joe_Black" <JoeBlack@newsg roups.nospam> wrote in message
            >> news:%23J3JPCdZ FHA.2796@TK2MSF TNGP10.phx.gbl. ..
            >>[/color]
            >
            > I see the problem, what about this then:
            >
            > Can I find the default mail account, and tell it to create an email with
            > my email address, subject and body in it. This would negate the need to
            > know any settings for SMTP etc. but would rely instead on an external app,
            > like outlook express for instance. This would also mean if the user had a
            > hotmail account that does not use SMTP my app could still send the email,
            > although the user themselveswould have to click "Send".
            >
            > Thanks
            >
            > Joe[/color]


            Comment

            • Mark Rae

              #7
              Re: Sending emails via c# code

              "Joe_Black" <JoeBlack@newsg roups.nospam> wrote in message
              news:%23RGThbcZ FHA.228@TK2MSFT NGP12.phx.gbl.. .
              [color=blue]
              > The only thing I can guarantee is that the target machine that this app is
              > installed on will have a mail account.[/color]

              Can you also guarantee that the target machine will have Internet accesss?
              If so, why not abandon the email approach altogether and write a webservice
              which the target machines will connect to?


              Comment

              • Joe_Black

                #8
                Re: Sending emails via c# code

                Adam Barker wrote:[color=blue]
                > I would've said it was far easier to use MailMessage than to start checking
                > for mail profiles. Outlook these days is quite locked down security wise so
                > I'm not sure how automatic you could make this. I would almost definitely go
                > for prompting for the smtp server.
                >
                > Depending on the context on which you're developing this app, could you not
                > use your own SMTP server and therefore hardcode this address in your app?
                > This way a) you wouldn't need to worry about the user knowing any mail
                > information, and b) you could enable relaying.
                >[/color]

                So, from the last paragrah above, does this mean i could simply use our
                own SMTP server, and send mails via that even though the users PC has no
                settings or knowledge of the existence of our smtp server?

                If this is so then it would definitely seem the best alternative

                What if our SMTP server needs an user name and password, if I hard coded
                it into my application could someone then hack the app and find our SMTP
                server info? I have little experience in the SMTP/POP3 programming world
                so these questions may be stupid...

                Many thanks

                Joe

                Comment

                • Joe_Black

                  #9
                  Re: Sending emails via c# code

                  Mark Rae wrote:[color=blue]
                  > "Joe_Black" <JoeBlack@newsg roups.nospam> wrote in message
                  > news:%23RGThbcZ FHA.228@TK2MSFT NGP12.phx.gbl.. .
                  >
                  >[color=green]
                  >>The only thing I can guarantee is that the target machine that this app is
                  >>installed on will have a mail account.[/color]
                  >
                  >
                  > Can you also guarantee that the target machine will have Internet accesss?
                  > If so, why not abandon the email approach altogether and write a webservice
                  > which the target machines will connect to?
                  >
                  >[/color]

                  Yes, they will have to have an internet connection on their machine as
                  part of the apps functionality is to connect to our hardware via an ADSL
                  link.

                  I'm not sure about the web service thing though, I have no real
                  experience with them so I'm not sure exactly what your suggesting? I
                  must admit though I wouldn't mind having a go with the web services.

                  Basically all I want to do is get information about plugin modules that
                  the user has installed on their machine, so that they can register these
                  modules to use them. I need to get the registration information from the
                  users machine to an email address on our mail server so that the people
                  generating the key codes to activate the modules can send an email back
                  to the user with the activation key.

                  I can't automate this via a web server app as I have been specifically
                  requested to perform the registration by email or phone.

                  Many thanks

                  Joe

                  Comment

                  • Adam Barker

                    #10
                    Re: Sending emails via c# code

                    You need to open up access to your SMTP server and essentially make it
                    public on the internet.

                    You could counteract the security issue by limiting its use to the IP
                    addresses of your clients, although this obviously has an admin overhead. If
                    you could do this though, it wouldn't matter if the SMTP server was
                    discovered by hacking your app. Chances are your server will be discovered
                    anyway.

                    "Joe_Black" <JoeBlack@newsg roups.nospam> wrote in message
                    news:uGAAehdZFH A.3364@TK2MSFTN GP12.phx.gbl...[color=blue]
                    > Adam Barker wrote:[color=green]
                    >> I would've said it was far easier to use MailMessage than to start
                    >> checking for mail profiles. Outlook these days is quite locked down
                    >> security wise so I'm not sure how automatic you could make this. I would
                    >> almost definitely go for prompting for the smtp server.
                    >>
                    >> Depending on the context on which you're developing this app, could you
                    >> not use your own SMTP server and therefore hardcode this address in your
                    >> app? This way a) you wouldn't need to worry about the user knowing any
                    >> mail information, and b) you could enable relaying.
                    >>[/color]
                    >
                    > So, from the last paragrah above, does this mean i could simply use our
                    > own SMTP server, and send mails via that even though the users PC has no
                    > settings or knowledge of the existence of our smtp server?
                    >
                    > If this is so then it would definitely seem the best alternative
                    >
                    > What if our SMTP server needs an user name and password, if I hard coded
                    > it into my application could someone then hack the app and find our SMTP
                    > server info? I have little experience in the SMTP/POP3 programming world
                    > so these questions may be stupid...
                    >
                    > Many thanks
                    >
                    > Joe[/color]


                    Comment

                    • Joe_Black

                      #11
                      Re: Sending emails via c# code

                      Adam Barker wrote:[color=blue]
                      > You need to open up access to your SMTP server and essentially make it
                      > public on the internet.
                      >
                      > You could counteract the security issue by limiting its use to the IP
                      > addresses of your clients, although this obviously has an admin overhead. If
                      > you could do this though, it wouldn't matter if the SMTP server was
                      > discovered by hacking your app. Chances are your server will be discovered
                      > anyway.
                      >[/color]

                      I'm Scared of that option.

                      I think I may just do as you suggested earlier and ask them for the SMTP
                      server information at initial start up. If they don't know it off hand
                      they will have to contact our customer support department who can guide
                      them through finding it.

                      Thanks a lot for your help Adam.

                      Joe

                      Comment

                      • Nick Malik [Microsoft]

                        #12
                        Re: Sending emails via c# code

                        Don't use their e-mail client. Use yours.

                        Bring them to a web page where they enter the info that they need. That
                        info is e-mailed from your server to the address you have. The format is
                        fine.

                        If you need to validate, then have them enter their e-mail address on the
                        page. Then send them an e-mail with a link. The link will contain a URL
                        code referring to their particular registration record. They click the
                        link, and you know that they received the e-mail, so the e-mail address can
                        be reasonably assumed to belong to them.

                        Alternative: set up a web service on your web server, and have the app send
                        data to it.

                        Don't use System.Web.Mail in client code. That is a server-side option.

                        --
                        --- Nick Malik [Microsoft]
                        MCSD, CFPS, Certified Scrummaster


                        Disclaimer: Opinions expressed in this forum are my own, and not
                        representative of my employer.
                        I do not answer questions on behalf of my employer. I'm just a
                        programmer helping programmers.
                        --
                        "Joe_Black" <JoeBlack@newsg roups.nospam> wrote in message
                        news:%23RGThbcZ FHA.228@TK2MSFT NGP12.phx.gbl.. .[color=blue]
                        > Hi all,
                        >
                        > I have googled this and found some answers but none that give me exactly
                        > what I'm after, maybe someone here can help.
                        >
                        > I have an app that will be distributed to users for their laptop and home
                        > PC's, I have no idea what operating system they are using although it will
                        > be at least Win 98, I also have no idea what mail client they will be
                        > using or which ISP their mail account is with. I would like to send an
                        > email from the app using their default mail account, I had a look at the
                        > System.Web.Mail classes, specifically MailMessage class, but this requires
                        > a mail server, how would I get this information from the system? also it
                        > requires a mail from field which I would like to get from the system
                        > without asking the user to enter it, again how is this achieved?
                        >
                        > Is there another way to do what I want to do, I know that there are the
                        > Indy components but I'd rather avoid having to distibute more Dll's,
                        > unless the Indy route is the best.
                        >
                        > The only thing I can guarantee is that the target machine that this app is
                        > installed on will have a mail account.
                        >
                        > Many thanks
                        >
                        > Joe[/color]


                        Comment

                        • Joe_Black

                          #13
                          Re: Sending emails via c# code

                          Just a reply to all you guys for your suggestions.

                          Many thanks

                          Joe

                          Comment

                          Working...