[bb] Please delete me by Yan [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:38

Previous topic - Next topic

BlitzBot

Title : Please delete me
Author : Yan
Posted : 1+ years ago

Description : ...

Code :
Code (blitzbasic) Select
...

Comments :


Yan(Posted 1+ years ago)

 Here's a small example...
;************************************************************************
;*** Blitz Mail Library Demo
;************************************************************************

Graphics 640, 480, 0, 2

; Add the MIME library
Include "BlitzMailInc.bb"

; Get the required parameters
name_from$ = Input$("Enter your name : ")

Repeat
mail_from$ = Input$("Enter your e-mail address : ")
Until mail_from$ <> "" And Instr(mail_from$, "@") > 0

Print

to_name$ = Input$("Enter the recipients name : ")

Repeat
to_mail$ = Input$("Enter the recipients e-mail address : ")
Until to_mail$ <> "" And Instr(to_mail$, "@") > 0

Print

subject$ = Input$("Enter subject text : ")

Print

server$ = Input$("Enter SMTP server name (mail/smtp.yourisp.TLD) : ")

; Add 'text.zip' as an include
;process_include$("text.zip")

; We're using an external file for the HTML. So, lets convert it to a string
tmp_html$ = file_to_string$("htmlmail.htm");Any HTML page should do

; Lets scan the HTML string for images, load and encode them. Then insert their CID into the relevant image tags
; If the HTML was in a different directory to this code - tmp_html$ = process_html$(tmp_html$, "HTML directory")
tmp_html$ = process_html$(tmp_html$)

; Now assemble all of the data into one MIME mail complete with relevant encoding.
html$ = build_mime$(tmp_html$, "Some Plain Text in case the receiving mail client can't cope with HTML.")

; The above could have been accomplished with...
;html$ = build_mime$(process_html$(file_to_string$("htmlmail.htm")), "Some Demo Text")

Print
Print "Sending Mail (for dial up networks you may have to connect manually first)"
Print
Delay 100
; Now send the mail

Print send_mail$(mail_from$, name_from$, to_mail$, to_name$, subject$, html$, server$)
; You may need to use...
; Print send_mail$(mail_from$, name_from$, to_mail$, to_name$, subject$, html$, server$, "account username", "account password", AUTH_ALL)

Print
Print "Any key to exit"
WaitKey()

End



Tom(Posted 1+ years ago)

 Nice work Ian, works a treat with authentication.ThanksTom


jd269(Posted 1+ years ago)

 Pretty good code.  Just wondering, how do you get it to work with image tags when the images are not hosted in your local directory?


octothorpe(Posted 1+ years ago)

 <div class="quote"> how do you get it to work with image tags when the images are not hosted in your local directory? </div>Before creating a new html_image in process_html$(), check to make sure the image file can be found in the local directory.  If not, do nothing: assume it's on the web and leave the image tag to the external image.


Yan(Posted 1+ years ago)

 What Octothorpe said! ;o)Or...If you don't want to embed *any* images, then simply don't call process_html()...(I probably should have given that function a more descriptive name);************************************************************************
;***                    Blitz Mail Library Demo
;************************************************************************

Graphics 640, 480, 0, 2

; Add the MIME library
Include "BlitzMailInc.bb"

; Get the required parameters
name_from$ = Input$("Enter your name : ")

Repeat
    mail_from$ = Input$("Enter your e-mail address : ")
Until mail_from$ <> "" And Instr(mail_from$, "@") > 0

Print

to_name$ = Input$("Enter the recipients name : ")

Repeat


    to_mail$ = Input$("Enter the recipients e-mail address : ")
Until to_mail$ <> "" And Instr(to_mail$, "@") > 0

Print

subject$ = Input$("Enter subject text : ")

Print

server$ = Input$("Enter SMTP server name (mail/smtp.yourisp.TLD) : ")

; Add 'text.zip' as an include
;process_include$("text.zip")

; We're using an external file for the HTML. So, lets convert it to a string
tmp_html$ = file_to_string$("htmlmail.htm");Any HTML page should do

; I don't want to embed the images, so I'll just qp encode the HTML.
tmp_html$ = qp_enc$(tmp_html$)

; Now assemble all of the data into one MIME mail complete with relevant encoding.
html$ = build_mime$(tmp_html$, "Some Plain Text in case the receiving mail client can't cope with HTML.")

Print
Print "Sending Mail (for dial up networks you may have to connect manually first)"
Print
Delay 100
; Now send the mail

Print send_mail$(mail_from$, name_from$, to_mail$, to_name$, subject$, html$, server$)
; You may need to use...
; Print send_mail$(mail_from$, name_from$, to_mail$, to_name$, subject$, html$, server$, "account username", "account password", AUTH_ALL)

Print
Print "Any key to exit"
WaitKey()

; Clean up (not needed here, but what the hell)
delete each inc_data
delete each html_image

End
@Tom - I'm glad you found a use for it. :o)


RGR(Posted 1+ years ago)

 Melvin that's super useful for me .. Thank you very much.I found a little error: In line 72 of the lib the var must be mailserver not maileserver ... only noticable if port is not 25 ;-)


Yan(Posted 1+ years ago)

 Oops...FixedCheers RaGR!


Pineapple(Posted 1+ years ago)

 Great Stuff... Works like a charm! :)Dabz


Ian Thompson(Posted 1+ years ago)

 Hi Ian, can you recommend any documents to better understand your code?


Yan(Posted 1+ years ago)

 I get all my information from 'The Junior Encyclopaedia of Space'. Okay...I don't... ;o)I used the SMTP/ESMTP, BASE64, SASL and MIME RFCs to write that code. I can't remember their numbers I'm afraid but a google should pop em up. The RFCs, although a bit wordy, are an excellent reference for anything intaweb related.@Dabz - Glad you found it useful. :o)


Ian Thompson(Posted 1+ years ago)

 Thank you, very helpfull. :) [/i]