Announcement

Collapse
No announcement yet.

Email text pasted from clipboard into a multiline textbox

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

  • Email text pasted from clipboard into a multiline textbox

    Appending <html><pre> to the text appears to work.
    Is there a better solution to email pasted text from the clipboard so courier properly aligns?
    It seems receiving email clients correctly strip the <html><pre> and it looks fine.




    https://www.tesla.com/roadster

  • #2
    If it is aligning properly, the email client is not "stripping" the <html> and <pre> tags, it is obeying them by displaying the content following the <pre> tag using a fixed width font and not stripping extra spaces etc.

    If you want formatted email, you have to use HTML (unless you are sure that the recipient is using MS Outlook when the abominiation of RTF and winMail.dat attachments will work- for non-Outlook clients, RTF is an absolute PITA.), so there is no "better" solution. Without the HTML, the email client is free to display the text in any font that it or the user selects.

    You should actually wrap your message in <html><body><pre>.....</pre></body></html> tags, but fortunately most email clients are fairly tolerant of non-standard HTML
    Last edited by Stuart McLachlan; 28 Oct 2018, 07:35 PM.

    Comment


    • #3
      Thank you!
      https://www.tesla.com/roadster

      Comment


      • #4
        Not sure if I understood your question properly, so my last post may be irrelevant. I just re-read the subject header and your post and it's not clear what you are actually asking.
        Are you talking about "emailing text which you have previously pasted into a textbox" or "pasting textinto a textbox from an email which you have received"?

        Comment


        • #5
          Pasted from clipboard into multiline textbox and then sending.
          It is working with the <html><pre>textbox data </pre></html> send email ...
          https://www.tesla.com/roadster

          Comment


          • #6
            Originally posted by Mike Doty View Post
            Pasted from clipboard into multiline textbox and then sending.
            It is working with the <html><pre>textbox data </pre></html> send email ...
            Adding the <html><pre> tag set is really kinda making up for a weakness in the mail client. By default, most mail clients will display a plain text message using a proportional font, hence the mis-alignment of the text. The tags declare the text as pre-formatted, which the client then displays using a fixed width font. There is usually a user option to use a fixed font for plain text messages, but then you are relying on the user having set that.
            Real programmers use a magnetized needle and a steady hand

            Comment


            • #7
              That makes sense and I need to move to proportional (since it looks better.)
              It sure is easy copying/pasting then sending using <html><pre>
              https://www.tesla.com/roadster

              Comment


              • #8
                Originally posted by Mike Doty View Post
                That makes sense and I need to move to proportional (since it looks better.)
                It sure is easy copying/pasting then sending using <html><pre>
                Just be aware that without the <pre> and resultant fixed width font, the recipient will see your text in whatever font they have selected in their email client. It is quite likely that they will have a different font selected in their mail reader and will not see it the way you do.

                (If sending me a plain text email which you wish to be displayed as you have formatted it, please ensure that it looks correct when displayed in 14 point Comic Sans with line wraps at 74 characters )


                Comment


                • #9
                  Originally posted by Bud Durland View Post

                  Adding the <html><pre> tag set is really kinda making up for a weakness in the mail client. By default, most mail clients will display a plain text message using a proportional font, hence the mis-alignment of the text. The tags declare the text as pre-formatted, which the client then displays using a fixed width font. There is usually a user option to use a fixed font for plain text messages, but then you are relying on the user having set that.
                  In Pegasus Mail I can toggle plain text display between fixed width and proportional by hitting F12

                  Comment


                  • #10
                    You can send both a plain text plus the text wrapped in HTML code and I believe the email reader will decide on the view. This is when you might want a text email client program or viewer to easily pick up the text without having to read HTML code maybe from an attracememt and scrap the text out of the html code.
                    p purvis

                    Comment


                    • #11
                      some code that i was holding back of for sending a single or many png files to a phone by text
                      the code came from this forum.
                      https://forum.powerbasic.com/forum/u...rce-code/43042
                      https://forum.powerbasic.com/forum/u...nd-email-class

                      i had some older code in a file named clsemail.inc that did not work and found newer code in the forum called clsemail.inc
                      I will supply all the credit when i formally post much of the bulk in a single thread for texting formatted text.

                      I already tried texting html code to a phone and in test the whole html contents are dropped from ATT Iphones which was my only testing.
                      I really did not think it was going to work anyways.
                      There is code here to send a text file and i was testing with that option to see the formatting on a sms message.

                      I would not even try using gmail as a source account as the logon method used here will fail
                      Even my email server would not let me send an email to an email address outside of the network from a location away from the server network for security purposes but it would let me send to an email address account on the same server.

                      i did make a change to m_Timeout in the clsemail2.inc listed here mostly for testing purposes and moved the code back to the original for this forum post.
                      Code:
                      ' m_Timeout     = 60000   '(60 seconds)
                       m_Timeout     = 15000   '(15 seconds)
                      after this code
                      Code:
                      WHILE INSTR(stexta,$CRLF)
                      REPLACE $CRLF WITH $LF IN stexta
                      WEND
                      add another loop
                      Code:
                      WHILE INSTR(stexta,$CR)
                      REPLACE $CR WITH $LF IN stexta
                      WEND
                      Code:
                      COMPILE EXE  
                      #INCLUDE "win32api.inc"
                      
                      #INCLUDE "clsEmail2.inc"
                      
                      
                      FUNCTION PBMAIN() AS LONG
                      
                         ' NOTES:
                         ' The 'SendTo', 'CC', 'BCC' fields can be a one address or a
                         ' semicolon(;) or comma(,) deliminated list of multiple addresses.
                         ' SMTP only allows 100 recipients max at a time (per rfc821), therefore
                         ' for large mailings you should break it into multiple emails.
                      
                         ' Multiple attachments can be sent by simply separating the file
                         ' names with a semicolon or comma.
                      
                         ' You can use 'Plain' text emails or 'HTML' emails, or 'Both'.
                         ' When sending "Both", the email client application will use whichever
                         ' one it can render based on the user's settings.
                      
                         ' Default values for the following that are already set by the
                         ' class (constructor). Change them here if you want a different value.
                         ' e.g.
                         ' cMail.ServerTimeOut = 60000  ' milliseconds  ' default is 60000
                         ' cMail.LocalHost     = "MySuperComputer"      ' default is localhost
                         ' cMail.CharSet       = "us-ascii"             ' default is iso-8859-1
                         ' cMail.MessageStyle  = "both"                 ' default is Plain
                      
                      
                         DIM sdate AS STRING
                         DIM stime AS STRING
                         DIM sdatetime AS STRING
                         DIM itime AS LONG
                         sdate=DATE$
                         stime=TIME$
                         itime=VAL(stime)
                         IF itime > 12& THEN itime=itime-12
                         sdatetime=MID$(sdate,1,2)+"/"+MID$(sdate,4,2)+"/"+MID$(sdate,9,2)+"_"+RIGHT$("00"+TRIM$(STR$(itime)),2)+":"+MID$(stime,4,2)
                      
                         DIM cMail AS EMailInterface
                         cMail = CLASS "clsEmail"
                         cMail.SMTPPort   = 25
                      
                         cMail.SMTPServer   = "smtpserver.com"
                        ' cMail.SMTPServer   = "smtpserveripaddress"
                      
                         cMail.SendFrom     = "sourceemailaccount@smtpserver.com"
                         cMail.SendTo       = "destinatinoemailaccountt@smtpserver.com"
                         cMail.CC           = ""
                         cMail.BCC          = ""
                         cMail.ReplyTo      = ""
                         cMail.Subject      = "my subject line "+sdatetime
                      
                         cMail.EnableAuth   = %TRUE
                         cMail.AuthType     = "AUTH LOGIN"
                         cMail.AuthUsername = "sourceemailaccount@smtpserver.com"
                         cMail.AuthPassword = "sourceemailaccounpassword"
                      
                      
                      
                      
                      
                      
                         OPEN "c:\temp\textfilename .txt" FOR BINARY AS 1
                         DIM stexta AS STRING
                         GET$ 1, LOF(1), stexta
                         CLOSE 1
                      
                      
                      
                         cMail.MessageStyle = "Plain"
                         cMail.Attachments  = "c:\temp\texttoimage.png"       ' eg. "myfilename.zip"
                      
                         ' Plain text email
                        ' cMail.PlainMessage = "This is my test message." & $CRLF & _
                        '                      "Line #2" & $CRLF & _
                        '                      "Last line."
                      
                         stexta=stexta+$CRLF
                         WHILE INSTR(stexta,$CRLF)
                           REPLACE $CRLF WITH $LF IN stexta
                         WEND
                         WHILE INSTR(stexta,$SPC+$LF)
                            REPLACE $SPC+$LF WITH $LF IN stexta
                         WEND
                        ' WHILE INSTR(stexta,$lf+$spc)
                        '    REPLACE $lf+$spc WITH $LF IN stexta
                        ' WEND
                         WHILE INSTR(stexta,$LF+$LF)
                           REPLACE $LF+$LF WITH $LF IN stexta
                         WEND
                         REPLACE $LF WITH $CRLF IN stexta
                      
                      
                      
                         cMail.PlainMessage = "" 'Date sent"+DATE$+ " "+TIME$+$CRLF '+stexta
                      
                      
                         ' HTML text email
                         cMail.HTMLMessage  = "<html>" & $CRLF  & _
                                              "<body>" & $CRLF  & _
                                              "<center><b>This Is a test!</b></center>" & $CRLF & _
                                              "</body>" & $CRLF & _
                                              "</html>" & $CRLF
                         cMail.HTMLMessage  = "<html>" & $CRLF  & _
                                              "<body>" & $CRLF  & _
                                              "<pre>+stexta</pre>" & $CRLF & _
                                              "</body>" & $CRLF & _
                                              "</html>" & $CRLF
                      
                      
                         ' Send the actual email and deal with any error/message response.
                         IF cMail.SendMail THEN
                            MSGBOX "Error sending E-mail! " & cMail.Response
                         ELSE
                            MSGBOX "Email(s) sent okay."
                         END IF
                      
                      
                      END FUNCTION
                      clsEmail2.inc
                      Code:
                      CLASS clsEmail     'clsEmail2.inc
                         INSTANCE m_Server       AS STRING
                         INSTANCE m_SMTPPort     AS LONG    ' RBoyd: added for port configuration
                         INSTANCE m_From         AS STRING
                         INSTANCE m_ReplyTo      AS STRING
                         INSTANCE m_TO           AS STRING
                         INSTANCE m_CC           AS STRING
                         INSTANCE m_BCC          AS STRING
                         INSTANCE m_Subject      AS STRING
                         INSTANCE m_PlainMessage AS STRING
                         INSTANCE m_HTMLMessage  AS STRING
                         INSTANCE m_Response     AS STRING
                         INSTANCE m_EnableAuth   AS LONG
                         INSTANCE m_AuthType     AS STRING
                         INSTANCE m_AuthUsername AS STRING
                         INSTANCE m_AuthPassword AS STRING
                         INSTANCE m_Style        AS STRING
                         INSTANCE m_Timeout      AS LONG
                         INSTANCE m_Attachments  AS STRING
                         INSTANCE m_LocalHost    AS STRING
                         INSTANCE m_CharSet      AS STRING
                          '------------------------------------------------------------
                         '  Private Class methods
                         '------------------------------------------------------------
                          '//
                         '//
                         CLASS METHOD CREATE()   ' Constructor
                            ' Initialize default properties
                            m_Timeout     = 60000   '(60 seconds)
                            m_CharSet     = "iso-8859-1"
                            m_Style       = "plain"
                            HOST NAME TO m_LocalHost
                         END METHOD
                          '//
                         '//
                         CLASS METHOD MimeEncode( BYVAL sFileData AS STRING ) AS STRING
                             LOCAL lBlock, lcBlocks, lByte1, lByte2, lByte3, lIndex1, lIndex2, lIndex3, lIndex4 AS LONG
                             LOCAL pInput, pOutput, pTable AS BYTE PTR
                             LOCAL sBase64, sResult, Pad AS STRING
                              sBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"   'Base64 table
                             Pad = STRING$(2 - (LEN(sFileData) - 1) MOD 3, "=")          'Calculate padding on Base64 stream
                              lcBlocks = (LEN(sFileData) + 2) \ 3                         'Round up the length of the input
                             IF lcBlocks * 3 > LEN(sFileData) THEN                       'data to a multiple of three
                               sFileData = LSET$(sFileData, lcBlocks * 3 USING $NUL)
                             END IF
                              sResult = SPACE$(lcBlocks * 4)                              'Allocate space for output string
                              pInput  = STRPTR(sFileData)                                 'Set up pointers so we can treat
                             pOutput = STRPTR(sResult)                                   'the data as byte streams
                             pTable  = STRPTR(sBase64)
                              FOR lBlock = 1 TO lcBlocks                                  'Loop through the input buffer
                               lByte1 = @pInput : INCR pInput                            'Get the next three binary data-
                               lByte2 = @pInput : INCR pInput                            'bytes to process
                               lByte3 = @pInput : INCR pInput
                                lIndex1 = lByte1 \ 4                                      'Translate 3 databytes to 4 Base64
                               lIndex2 = (lByte1 AND 3) * 16 + lByte2 \ 16               'table indices
                               lIndex3 = (lByte2 AND 15) * 4 + lByte3 \ 64
                               lIndex4 = lByte3 AND 63
                                @pOutput = @pTable[lIndex1] : INCR pOutput                'Use Base64 table to encode the
                               @pOutput = @pTable[lIndex2] : INCR pOutput                'output string
                               @pOutput = @pTable[lIndex3] : INCR pOutput
                               @pOutput = @pTable[lIndex4] : INCR pOutput
                             NEXT
                             RSET ABS sResult = Pad                                        'Merge in the padding bytes
                             METHOD = sResult
                         END METHOD
                          '//
                         '//
                         CLASS METHOD GetMailDateTime() AS STRING
                             ' Retrieve the current time and date to put in E-mail header format
                             LOCAL szFormat   AS ASCIIZ * 40
                             LOCAL szTemp     AS ASCIIZ * 40
                             LOCAL sResult    AS STRING
                             LOCAL t          AS SYSTEMTIME
                             LOCAL sUCTOffset AS STRING
                             LOCAL tzi        AS TIME_ZONE_INFORMATION
                              GetLocalTime t
                              szFormat = "ddd',' dd MMM yyyy"
                             GetDateFormat %LANG_INVARIANT, 0, t, szFormat, szTemp, SIZEOF(szTemp)   '%LANG_INVARIANT in other countries
                             sResult = szTemp
                              szFormat = "HH':'mm':'ss"
                             GetTimeFormat %LANG_INVARIANT, 0, t, szFormat, szTemp, SIZEOF(szTemp)   'LANG_INVARIANT in other countries
                              SELECT CASE GetTimeZoneInformation(tzi)
                             CASE %TIME_ZONE_ID_DAYLIGHT
                                 sUCTOffset = IIF$((tzi.bias + tzi.DaylightBias) <= 0, "+", "-") _
                                            + FORMAT$(ABS(tzi.bias + tzi.DaylightBias) \ 60, "00") _
                                            + FORMAT$(ABS(tzi.bias + tzi.DaylightBias) MOD 60, "00")
                             CASE %TIME_ZONE_ID_STANDARD
                                 sUCTOffset = IIF$((tzi.bias + tzi.StandardBias) <= 0, "+", "-") _
                                            + FORMAT$(ABS(tzi.bias + tzi.StandardBias) \ 60, "00") _
                                            + FORMAT$(ABS(tzi.bias + tzi.StandardBias) MOD 60, "00")
                             CASE ELSE
                                 sUCTOffset = "-0000"
                             END SELECT
                              METHOD = sResult & " " & szTemp & " " & sUCTOffset
                          END METHOD
                          '------------------------------------------------------------
                         '  End of Private Class methods
                         '------------------------------------------------------------
                          '------------------------------------------------------------
                         '  Public Interface
                         '------------------------------------------------------------
                          '//
                         '//
                         INTERFACE EMailInterface: INHERIT IUNKNOWN
                             PROPERTY GET SMTPServer() AS STRING
                               PROPERTY = m_Server
                            END PROPERTY
                            PROPERTY SET SMTPServer( BYVAL sServerName AS STRING )
                               m_Server = RTRIM$(sServername)
                            END PROPERTY
                             ' RBoyd: Added this get/set block for port configuration
                            PROPERTY GET SMTPPort() AS LONG
                               PROPERTY = m_SMTPPort
                            END PROPERTY
                            PROPERTY SET SMTPPort( BYVAL nSMTPPort AS LONG )
                               m_SMTPPort = nSMTPPort
                            END PROPERTY
                             PROPERTY GET SendFrom() AS STRING
                               PROPERTY = m_From
                            END PROPERTY
                            PROPERTY SET SendFrom( BYVAL sRecipientFrom AS STRING )
                               m_From = RTRIM$(sRecipientFrom)
                            END PROPERTY
                             PROPERTY GET SendTo() AS STRING
                               PROPERTY = m_TO
                            END PROPERTY
                            PROPERTY SET SendTo( BYVAL sRecipientTo AS STRING )
                               m_TO = RTRIM$(sRecipientTo)
                            END PROPERTY
                             PROPERTY GET CC() AS STRING
                               PROPERTY = m_CC
                            END PROPERTY
                            PROPERTY SET CC( BYVAL sRecipientCC AS STRING )
                               m_CC = RTRIM$(sRecipientCC)
                            END PROPERTY
                             PROPERTY GET BCC() AS STRING
                               PROPERTY = m_BCC
                            END PROPERTY
                            PROPERTY SET BCC( BYVAL sRecipientBCC AS STRING )
                               m_BCC = RTRIM$(sRecipientBCC)
                            END PROPERTY
                             PROPERTY GET ReplyTo() AS STRING
                               PROPERTY = m_ReplyTo
                            END PROPERTY
                            PROPERTY SET ReplyTo( BYVAL sReplyTo AS STRING )
                               m_ReplyTo = RTRIM$(sReplyTo)
                            END PROPERTY
                             PROPERTY GET Subject() AS STRING
                               PROPERTY = m_Subject
                            END PROPERTY
                            PROPERTY SET Subject( BYVAL sSubject AS STRING )
                               m_Subject = sSubject
                            END PROPERTY
                             PROPERTY GET PlainMessage() AS STRING
                               PROPERTY = m_PlainMessage
                            END PROPERTY
                            PROPERTY SET PlainMessage( BYVAL sPlainMessage AS STRING )
                               m_PlainMessage = sPlainMessage
                            END PROPERTY
                             PROPERTY GET HTMLMessage() AS STRING
                               PROPERTY = m_HTMLMessage
                            END PROPERTY
                            PROPERTY SET HTMLMessage( BYVAL sHTMLMessage AS STRING )
                               m_HTMLMessage = sHTMLMessage
                            END PROPERTY
                             PROPERTY GET Response() AS STRING
                               PROPERTY = m_Response
                            END PROPERTY
                             PROPERTY GET EnableAuth() AS LONG
                               PROPERTY = m_EnableAuth
                            END PROPERTY
                            PROPERTY SET EnableAuth( BYVAL nEnableAuth AS LONG )
                               m_EnableAuth = nEnableAuth
                            END PROPERTY
                             PROPERTY GET AuthType() AS STRING
                               PROPERTY = m_AuthType
                            END PROPERTY
                            PROPERTY SET AuthType( BYVAL sAuthType AS STRING )
                               m_AuthType = RTRIM$(sAuthType)
                            END PROPERTY
                             PROPERTY GET AuthUserName() AS STRING
                               PROPERTY = m_AuthUserName
                            END PROPERTY
                            PROPERTY SET AuthUserName( BYVAL sAuthUserName AS STRING )
                               m_AuthUserName = RTRIM$(sAuthUserName)
                            END PROPERTY
                             PROPERTY GET AuthPassword() AS STRING
                               PROPERTY = m_AuthPassword
                            END PROPERTY
                            PROPERTY SET AuthPassword( BYVAL sAuthPassword AS STRING )
                               m_AuthPassword = RTRIM$(sAuthPassword)
                            END PROPERTY
                             PROPERTY GET MessageStyle() AS STRING
                               PROPERTY = m_Style
                            END PROPERTY
                            PROPERTY SET MessageStyle( BYVAL sMessageStyle AS STRING )
                               m_Style = UCASE$(RTRIM$(sMessageStyle))
                            END PROPERTY
                             PROPERTY GET ServerTimeout() AS LONG
                               PROPERTY = m_Timeout
                            END PROPERTY
                            PROPERTY SET ServerTimeout( BYVAL nServerTimeout AS LONG )
                               m_Timeout = nServerTimeout
                            END PROPERTY
                             PROPERTY GET Attachments() AS STRING
                               PROPERTY = m_Attachments
                            END PROPERTY
                            PROPERTY SET Attachments( BYVAL sAttachments AS STRING )
                               m_Attachments = RTRIM$(sAttachments)
                            END PROPERTY
                             PROPERTY GET LocalHost() AS STRING
                               PROPERTY = m_LocalHost
                            END PROPERTY
                            PROPERTY SET LocalHost( BYVAL sLocalHost AS STRING )
                               m_LocalHost = RTRIM$(sLocalHost)
                            END PROPERTY
                             PROPERTY GET CharSet() AS STRING
                               PROPERTY = m_CharSet
                            END PROPERTY
                            PROPERTY SET CharSet( BYVAL sCharSet AS STRING )
                               m_CharSet = RTRIM$(sCharSet)
                            END PROPERTY
                             '//
                            '//
                            METHOD SendMail() AS LONG
                               LOCAL hTCP           AS LONG
                               LOCAL y              AS LONG
                               LOCAL f              AS LONG
                               LOCAL z              AS LONG
                               LOCAL NumLines       AS LONG
                               LOCAL errcode        AS LONG
                               LOCAL sTmp           AS STRING
                               LOCAL sBuffer        AS STRING
                               LOCAL sBoundary      AS STRING
                               LOCAL sAllRecipients AS STRING
                               LOCAL NumAttachments AS LONG
                                ' Make a unique file data boundary marker
                               sBoundary = "Boundary." & REMOVE$(GUIDTXT$(GUID$), ANY "{-}")
                                ' Connect to E-mail server (mailhost)
                               hTCP = FREEFILE
                               ' RBoyd: Configurable port change
                               IF m_SMTPPort = 0 THEN
                                  TCP OPEN "smtp" AT m_Server AS hTCP TIMEOUT m_Timeout
                               ELSE
                                  TCP OPEN PORT m_SMTPPort AT m_Server AS hTCP TIMEOUT m_Timeout
                               END IF
                                m_Response = "Cannot connect to E-mail server: " & m_Server
                               IF ERR THEN GOTO SendError
                                TCP LINE hTCP, m_Response
                               IF LEFT$(m_Response, 3) <> "220" THEN GOTO SendError
                                ' Get the local host name
                               IF RTRIM$(m_LocalHost) = "" THEN m_LocalHost = "localhost"
                                ' Greet the mailhost
                               TCP PRINT hTCP, "HELO " & m_LocalHost
                               TCP LINE hTCP, m_Response
                               IF LEFT$(m_Response, 3) <> "250" THEN GOTO SendError
                                ' Send authentication if required
                               IF m_EnableAuth THEN
                                    DO WHILE NOT EOF(hTCP)
                                       TCP LINE hTCP, sBuffer
                                       errcode = VAL(LEFT$(sBuffer, 3))
                                   LOOP
                                   TCP PRINT hTCP, m_AuthType
                                    DO WHILE NOT EOF(hTCP)
                                       TCP LINE hTCP, sBuffer
                                       errcode = VAL(LEFT$(sBuffer, 3))
                                   LOOP
                                    IF errcode = 334 THEN
                                       sTmp = Me.MimeEncode(m_AuthUsername)     ' UserId (might be the same as the POP3 UserId)
                                       TCP PRINT hTCP, sTmp
                                       DO WHILE NOT EOF(hTCP)
                                           TCP LINE hTCP, sBuffer
                                           errcode = VAL(LEFT$(sBuffer, 3))
                                       LOOP
                                       IF errcode = 334 THEN
                                           sTmp = Me.MimeEncode(m_AuthPassword) ' Password (might be the same as the POP3 password)
                                           TCP PRINT hTCP, sTmp
                                           DO WHILE NOT EOF(hTCP)
                                               TCP LINE hTCP, sBuffer
                                               errcode = VAL(LEFT$(sBuffer, 3))
                                           LOOP
                                       END IF
                                   END IF
                                END IF
                                ' Tell the mailhost who we are
                               REM tcp print hTCP, "MAIL FROM:<" & m_From & ">"
                               y = INSTR(m_from, "<")
                               IF y THEN
                                TCP PRINT hTCP, "MAIL FROM:" & MID$(m_from,y)
                              ELSE
                                TCP PRINT hTCP, "MAIL FROM:<" & m_From & ">"
                              END IF
                               TCP LINE hTCP, m_Response
                              IF LEFT$(m_Response, 3) <> "250" THEN GOTO SendError
                                ' Tell the mailhost who the message is for
                               ' There could be multiple recipients so iterate through
                               ' the semicolon or comma deliminated list. The total RCPT
                               ' list is the combination of the TO, CC, BCC lists.
                               sAllRecipients = m_TO & ";" & m_CC & ";" & m_BCC
                                NumLines = PARSECOUNT(sAllRecipients, ANY ";,")
                               REDIM sArray(1 TO NumLines) AS STRING
                               PARSE sAllRecipients, sArray(), ANY ";,"
                                FOR y = 1 TO NumLines
                                  sTmp = RTRIM$(sArray(y))
                                  IF LEN(sTmp) THEN
                                     TCP PRINT hTCP, "RCPT TO:<" & sTmp & ">"
                                     TCP LINE hTCP, m_Response
                                     IF LEFT$(m_Response, 3) <> "250" THEN GOTO SendError
                                  END IF
                               NEXT
                                ' Send the message
                               TCP PRINT hTCP, "DATA"
                               TCP LINE hTCP, m_Response
                               IF LEFT$(m_Response, 3) <> "354" THEN GOTO SendError
                                ' The E-mail header
                               TCP PRINT hTCP, "Date: " & Me.GetMailDateTime
                               TCP PRINT hTCP, "From: " & m_From
                                TCP PRINT hTCP, "To: " & m_To
                                IF LEN(m_ReplyTo) THEN
                                  TCP PRINT hTCP, "Reply-To: " & m_ReplyTo
                               END IF
                                IF LEN(m_CC) THEN
                                  TCP PRINT hTCP, "Cc: "  & m_CC
                               END IF
                                ' Obviously we won't output the BCC list to the email
                                TCP PRINT hTCP, "Subject: " & m_Subject
                                TCP PRINT hTCP, "X-Mailer: pMailer Mail"
                               TCP PRINT hTCP, "MIME-Version: 1.0"
                                TCP PRINT hTCP, "Content-Type: multipart/mixed; boundary=" & $DQ & sBoundary & $DQ
                               TCP PRINT hTCP, ""
                                ' Create a main E-mail body section for the Plain message.
                               ' Break the message down into lines
                                IF (m_Style = "PLAIN") OR (m_Style = "BOTH") THEN
                                  TCP PRINT hTCP, "--" & sBoundary
                                  TCP PRINT hTCP, "Content-Type: text/plain; charset=" & $DQ & m_CharSet & $DQ
                                  TCP PRINT hTCP, "Content-Transfer-Encoding: 7bit"
                                  TCP PRINT hTCP, ""
                                  ' Any crlf pairs or plain lf's will be replaced with cr's for easy parsing
                                  REPLACE $CRLF WITH $CR IN m_PlainMessage
                                  REPLACE $LF   WITH $CR IN m_PlainMessage
                                   NumLines = PARSECOUNT( m_PlainMessage, $CR )
                                  REDIM sArray(1 TO NumLines) AS STRING
                                  PARSE m_PlainMessage, sArray(), $CR
                                   FOR y = 1 TO NumLines
                                     TCP PRINT hTCP, sArray(y)
                                  NEXT
                               END IF
                                IF (m_Style = "HTML") OR (m_Style = "BOTH") THEN
                                  TCP PRINT hTCP, "--" & sBoundary
                                  TCP PRINT hTCP, "Content-Type: text/html; charset=" & $DQ & m_CharSet & $DQ
                                  TCP PRINT hTCP, "Content-Transfer-Encoding: 7bit"
                                  TCP PRINT hTCP, ""
                                  ' Any crlf pairs or plain lf's will be replaced with cr's for easy parsing
                                  REPLACE $CRLF WITH $CR IN m_HTMLMessage
                                  REPLACE $LF   WITH $CR IN m_HTMLMessage
                                   NumLines = PARSECOUNT( m_HTMLMessage, $CR )
                                  REDIM sArray(1 TO NumLines) AS STRING
                                  PARSE m_HTMLMessage, sArray(), $CR
                                   FOR y = 1 TO NumLines
                                     TCP PRINT hTCP, sArray(y)
                                  NEXT
                               END IF
                                ' Create the attachment body section
                               IF LEN(m_Attachments) > 0 THEN
                                  REM NumAttachments = PARSECOUNT( m_Attachments, ";," )
                                  NumAttachments = PARSECOUNT( m_Attachments, ANY ";," ) '8/17/13
                                  REDIM sArray(1 TO NumAttachments) AS STRING
                                  REM PARSE m_Attachments, sArray(), ";,"
                                  PARSE m_Attachments, sArray(), ANY ";," '8/17/13
                                   FOR y = 1 TO NumAttachments
                                     IF DIR$(sArray(y)) = "" THEN ITERATE FOR
                                      f = FREEFILE
                                     OPEN sArray(y) FOR BINARY AS #f
                                     GET$ #f, LOF(f), sBuffer
                                     CLOSE #f
                                      ' Encode the file
                                     sBuffer = Me.MimeEncode( sBuffer )
                                      TCP PRINT hTCP, "--" & sBoundary
                                     TCP PRINT hTCP, "Content-Type: application/octet-stream; name=" & $DQ & PATHNAME$(NAMEX, sArray(y)) & $DQ
                                     TCP PRINT hTCP, "Content-Transfer-Encoding: base64"
                                     TCP PRINT hTCP, ""
                                      ' Write the encoded data in lines of 76 characters.  Add an equality
                                     ' character if the last line is less than 76 bytes long
                                     FOR z = 1 TO LEN(sBuffer) STEP 76
                                        IF LEN(sBuffer) - z >= 76 THEN
                                           TCP PRINT hTCP, MID$(sBuffer, z, 76)
                                        ELSE
                                           TCP PRINT hTCP, MID$(sBuffer, z) & "="
                                        END IF
                                     NEXT
                                   NEXT
                               END IF
                                ' Send the terminating boundary marker
                               TCP PRINT hTCP, "--" & sBoundary & "--"
                                ' Now finish the E-mail off as we're done sending the message
                               TCP PRINT hTCP, "."
                               TCP LINE hTCP, m_Response
                               IF LEFT$(m_Response, 3) <> "250" THEN GOTO SendError
                                ' Say goodbye
                               TCP PRINT hTCP, "QUIT"
                               TCP LINE hTCP, m_Response
                               IF LEFT$(m_Response, 3) <> "221" THEN GOTO SendError
                                TCP CLOSE hTCP
                                EXIT METHOD
                       SendError:
                              METHOD = %TRUE    ' error occurred
                             END METHOD
                          END INTERFACE
                          '------------------------------------------------------------
                         '  End of Public Interface
                         '------------------------------------------------------------
                       END CLASS
                       FUNCTION ISEMAIL(BYVAL e AS STRING, MailAddr AS STRING) AS LONG
                      '------------------------------------------------------------
                      ' verifies that the passed string contains at least one
                      ' valid e-mail address and returns a fixed up version
                      '------------------------------------------------------------
                        LOCAL Mask    AS STRING
                        LOCAL p       AS LONG
                        LOCAL l       AS LONG
                         MailAddr = ""
                        IF LEN(e) = 0 THEN
                          FUNCTION = 0
                          EXIT FUNCTION
                        END IF
                         Mask = "([a-z0-9._-]+)(@[a-z0-9._-]+)(\.[a-z]+)"
                        REGEXPR Mask IN e TO p,l
                         IF l > 0 THEN MailAddr = "<" + MID$(e,p,l) + ">"
                         FUNCTION = (l > 0)
                       END FUNCTION
                      p purvis

                      Comment


                      • #12
                        I've used this code before with godaddy and others, but have never been able to get to work with Gmail.
                        Pop and Smtp are enabled in Gmail and lowered the security level or whatever they call it so Oauth isn't needed.
                        Anyone get the code to work with Gmail?

                        cMail.SMTPServer = "smtp.gmail.com"
                        cMail.SMTPPort = 465
                        cMail.AuthUserName = "fullusername@gmail.com"
                        cMail.AuthPassword = "yourpassword"
                        cMail.EnableAuth = %TRUE
                        cMail.AuthType = "AUTH LOGIN"
                        cMail.MessageStyle = "both"
                        cMail.MessageStyle = "Plain"
                        cMail.SendFrom = "myaccount@gmail.com"
                        cMail.SendTo = "myaccount@gmail.com
                        cMail.ReplyTo = cMail.SendTo

                        https://www.tesla.com/roadster

                        Comment


                        • #13
                          Here is the link to Paul's email class and the changes were consolidated by me into clsEmail2.inc in one of the final threads.
                          https://forum.powerbasic.com/forum/u...nd-email-class
                          Jose Roca's CDO code (post #11 in link above works fine with Gmail.)
                          ot sure why I can't get Paul's class to work with Gmail

                          Now using CDO instead of html with <pre> (which didn't allow hyperlinks.)
                          The text correctly aligns and html code also displays correctly using iMsg.TextBody.
                          The copy and paste into the multiline textbox will no longer be needed.
                          I will now shell to email program when needed.

                          Example of new program:
                          sFile = COMMAND$
                          OPEN sFile FOR BINARY AS #hFile
                          GET$ #hfile,LOF(hfile),s
                          CLOSE #hFile
                          iMsg.TextBody = s
                          Last edited by Mike Doty; 3 Nov 2018, 03:48 AM.
                          https://www.tesla.com/roadster

                          Comment

                          Working...
                          X