• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Writing code to send an email with HTML format body in Visual Basic

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Writing code to send an email with HTML format body in Visual Basic

    Hi

    I’m trying to write some VB code to send an email where the body is formatted in HTML (with the aim of including a hyperlink in the body eventually once I get it working), but it’s not working, in that I get no email being generated. The code is updated in Visual Studio 6.

    Here’s the email code I’m using:

    Set objMail = New MailSender
    objMail.Host = sMailHost
    objMail.From = sMailFrom
    objMail.AddAddress sMailRecipient
    objMail.Subject = "Dummy email subject" '& ": " & sFilename
    objMail.MailFormat = objMail.olFormatHTML
    objMail.BodyFormat = objMail.olFormatHTML
    objMail.HTMLBody = "<html>Test email format HTML</html>"
    objMail.Send
    Set objMail = Nothing

    I added the MailFormat and BodyFormat settings based on what I found from searching Google. I've also tried setting them to values of 0 and 2, as also suggested on Google.

    I know the email process works, because if I change it to normal text format in the same program it does work, like this:

    Set objMail = New MailSender
    objMail.Host = sMailHost
    objMail.From = sMailFrom
    objMail.AddAddress sMailRecipient
    objMail.Subject = "Dummy email subject" '& ": " & sFilename
    objMail.Body = "Test email format normal"
    objMail.Send
    Set objMail = Nothing

    Any suggestions how to get the HTML version of the email working would be greatly appreciated.

    Thanks
    Moose

    #2
    Have not written a line of code in years but a quick google suggests there is an "ishtml" property in the mail sender object which you need to set to true for html email. Ref: http://www.aspemail.com/manual_02.html

    Comment


      #3
      Bloody hell, have I been transported 20 years back in time...

      Comment


        #4
        Originally posted by Einstein Jnr View Post
        Have not written a line of code in years but a quick google suggests there is an "ishtml" property in the mail sender object which you need to set to true for html email. Ref: AspEmail.com - User Manual Chapter 2: Getting Started
        Thank you young Einstein, that worked splendidly

        I probably should have spotted that, but sometimes it's a case of not seeing the wood for the trees.

        And yes DP, maybe that's why I'm having trouble supporting this effing system, because it was written 20+ years ago and the people who wrote it have all been made redundant or died.

        Comment


          #5
          Maybe it's something I wrote back in my day - best of luck supporting it.

          Comment


            #6
            Originally posted by zeitghost
            Can't have been me, I'd have written it in FORTRAN.
            I learned to program in Forth, no wonder my brain is screwed.

            Comment


              #7
              Originally posted by DimPrawn View Post
              I learned to program in Forth, no wonder my brain is screwed.
              Pascal here no wonder I was put off going down the developer route if the truth be known z80 machine code was my encounter with coding

              Comment


                #8
                Originally posted by Moose423956 View Post
                And yes DP, maybe that's why I'm having trouble supporting this effing system, because it was written 20+ years ago and the people who wrote it have all been made redundant or died.

                On the plus side the fewer people with the skills the higher the rate becomes. I expect there are people with 50 years COBOL experience on a better rate than those with eff all experience of the latest reinvention of the coding wheel.

                I often wondered why I chose IT and have to re-skill every few years to stay up to date every time M$ and co come up with a 'new improved' way of getting data out of a database onto a screen, when a plumber or brickie can have decades of experience and rake it in for a seemingly easier life.

                As such I may not bother with the new incarnations and go for legacy contracts that may be fewer in frequency but I'll probably be the only one going for the interview.
                Maybe tomorrow, I'll want to settle down. Until tomorrow, I'll just keep moving on.

                Comment


                  #9
                  Originally posted by Hobosapien View Post
                  On the plus side the fewer people with the skills the higher the rate becomes. I expect there are people with 50 years COBOL experience on a better rate than those with eff all experience of the latest reinvention of the coding wheel.

                  I often wondered why I chose IT and have to re-skill every few years to stay up to date every time M$ and co come up with a 'new improved' way of getting data out of a database onto a screen, when a plumber or brickie can have decades of experience and rake it in for a seemingly easier life.

                  As such I may not bother with the new incarnations and go for legacy contracts that may be fewer in frequency but I'll probably be the only one going for the interview.
                  Quite. It's a young mans game keeping at the bleeding edge. Specialisation can be lucrative but you must be prepared to move around and in the long run it's risky. Best to specialise but keep a reasonably current base skillset to fall back on. For this to be possible your specialisation must use those skills somehow. This is working out ok for me anyway. Managed specialisation risk.

                  Comment


                    #10
                    Originally posted by Hobosapien View Post
                    I often wondered why I chose IT and have to re-skill every few years to stay up to date every time M$ and co come up with a 'new improved' way of getting data out of a database onto a screen, when a plumber or brickie can have decades of experience and rake it in for a seemingly easier life.
                    I've been saying this for years. When I went to college to study electronics after I finished school, my school friend went to the same college to study brick laying and building. That was the last time he has ever studied or learned anything new (work related) in nearly 30 years. I on the other hand, then went on to University to study computer science, and have been studying and learning new software dev skills every day since, including the constant certification treadmill.

                    He's never been on the bench and has plenty of money, his own house paid off and a collection of rental properties also all paid off. After work he's down the pub or playing golf. I'm learning Amazon Web Service certification.

                    IT is truly an appalling long term career choice.

                    Comment

                    Working...
                    X