Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

HTML Mail Script - Can Field Variable Values be included

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

    HTML Mail Script - Can Field Variable Values be included

    The following script works ok for me to send emails.
    It is added to an update event in a Grid
    Can someone please help as to how it can be enhanced to include field values?

    -----------------------------
    function AfterUpdateRecord as v (e as p)

    vTo = "[email protected]"
    vBcc = ""
    dim pm as P
    dim ps as P
    dim email_result as l

    vMessageStr = "here is may messsage."

    flag = email_smtp_open(ps, "mail.webside.com", 25, "[email protected]", "abccde")
    if flag = .f. then
    'report an error to the user
    end
    end if
    pm._to = vTo
    pm._bcc = vBcc

    pm.from = "[email protected]"
    pm.from_alias = "This is My Alias Name"
    pm.subject = "Subject of Email"
    pm.attachments = ""
    pm.html_message = "<HTML>Here is my message ee ee ee </HTML>"

    email_result = email_smtp_send(pm, ps)
    email_smtp_close(ps)
    end function

    #2
    Re: HTML Mail Script - Can Field Variable Values be included

    Here's a wrapper I wrote for sending email:

    Code:
    FUNCTION sendEmail AS P (e AS P, emailNum AS N = "0")
    	
    	'This function is pretty much a wrapper for email_smtp_send.
    	'It is written in XBASIC using a few references.
    	' http://wiki.alphasoftware.com/EMAIL_SMTP_OPEN+Function
    	' http://wiki.alphasoftware.com/EMAIL_SMTP_SEND+Function
    	' http://wiki.alphasoftware.com/EMAIL_SMTP_CLOSE+Function
    	
    	'The pointer `e` can contain:
    	'	e.from			C	=	Default = Whatever the username is set to. The sender's email address
    	'	e.from_alias	C	=	The sender's name
    	'	e.to			C	=	The recipient list. Multiple entries should be seperated via commas
    	'	e.cc			C	=	The CC list. Multiple entries should be seperated via commas
    	'	e.bcc			C	=	The BCC list. Multiple entries should be seperated via commas
    	'	e.subject		C	=	The subject of the email. THIS WILL OVERRIDE emailNum.
    	'	e.message		C	=	The body of a text message. THIS WILL OVERRIDE emailNum.
    	'	e.html_message	C	=	The body of a HTML message. THIS WILL OVERRIDE emailNum.
    	'	e.attachments	C	=	A semi-colon (;), comma, or CR-LF delimited list of filenames.
    	'	e.variables		P	=	IMPORTANT!!! These are the variables that are going to be
    	'									 merged with the emailNum that you specify.
    	'									 IT IS UP TO YOU!!! to have the correct
    	'									 variables specified!!!!!!!!!!!!!!!!!!!
    	'	e.lrelated		L	=	Default = .F. Attachments are seperate files, .T. for Embedded
    	'	e.returnreceipt	L	=	Default = .F. This will ask the sender for a read receipt.
    	
    	'emailNum is the id (Primary Key) of the Email being sent
    	'from the gen_email table in the global schema of the database.
    	'This is an OPTIONAL argument, if it is not specified, the 
    	'function will never even open the database.
    
    	'This function will return a pointer variable that contains the following
    	'	q.result		L	=	.T. if success, .F. if failed
    	'	q.resultText	C	=	This will contain ps.buffer (The result of the smtp_send)
    	'							Otherwise this will contain the error.
    	
    	' 			CONSTANTS NEED TO BE SET HERE!
    	' smtp_server			 =	 The host name of the STMP server.
    	dim smtp_server as c	 =	 "smtp.dazser.com"
    
    	' Port					 =	 The port for the smtp server
    	dim port as n			 = 	 25
    	
    	' Username				 =	 The user name of the account we're sending from
    	dim username as c		 =	 "[email protected]"
    	
    	' Password				 =	 The password of the user account
    	dim password as c		 =	 "thisisnotmypassword"
    	
    
    	' Other variables needed
    	dim flag as l
    	dim q as p
    	dim pm as p
    	dim ps as p
    	
    	if emailNum != 0 then
    
    		'This will run only if e.variables is set
    		'Basically, it will run if the email is being merged from the database
    		dim globalcn as sql::connection
    		dim rs as sql::ResultSet	
    		dim sqlCommand as c 
    	
    		'Open SQL Connection
    		flag = globalcn.Open("::Name::global")
    		if flag = .f. then
    			q.result = .F.
    			q.resultText = globalcn.CallResult.text
    			sendEmail = q
    		    end
    		end if
    
    		'get email from database
    		sqlCommand = "SELECT * FROM gen_email WHERE id = " + emailNum
    		flag = globalcn.Execute(sqlCommand)
    		if flag = .f. then
    			q.result = .F.
    			q.resultText = globalcn.CallResult.text
    			sendEmail = q
    			end
    		end if
    
    		'process email
    		rs = globalcn.ResultSet
    		
    		dim subject as c = rs.data("subject")
    		if eval_valid("subject") then
    			pm.subject = evaluate_string(subject, e.variables)	
    		end if
    		
    		dim html_msg as c = rs.data("content")
    		if eval_valid("html_msg") then
    			pm.html_message = evaluate_string(html_msg, e.variables)	
    		end if
    		
    		dim msg as c = rs.data("text")
    		if eval_valid("text") then
    			pm.message = evaluate_string(msg, e.variables)	
    		end if
    		
    		dim attachments as c = rs.data("attachments")
    		if attachments != "" then
    			pm.attachments = evaluate_string(attachments, e.variables)	
    		end if
    				
    		'cleanup
    		globalcn.FreeResult()
    		globalcn.Close()
    		delete globalcn
    		delete rs
    	
    	end if
    
    	'Go through all the variables in e!!!
    	'	e.from			C	=	The sender's email address
    	if eval_valid("e.from") then
    		pm.from = e.from
    	else
    		pm.from = username
    	end if
    
    	'	e.from_alias	C	=	The sender's name
    	if eval_valid("e.from_alias") then
    		pm.from_alias = e.from_alias
    	end if
    	
    	'	e.to			C	=	The recipient list. Multiple entries should be seperated via commas
    	if eval_valid("e.to") then
    		pm.to = e.to
    	else
    		q.result = .F.
    		q.resultText = "e.to not specified. Please give a valid CSV list."
    		sendEmail = q
    		end
    	end if
    	
    	'	e.cc			C	=	The CC list. Multiple entries should be seperated via commas
    	if eval_valid("e.cc") then
    		pm.cc = e.cc
    	end if
    	
    	'	e.bcc			C	=	The BCC list. Multiple entries should be seperated via commas
    	if eval_valid("e.bcc") then
    		pm.cc = e.bcc
    	end if
    	
    	'	e.subject		C	=	The subject of the email. THIS WILL OVERRIDE emailNum.
    	if eval_valid("e.subject") then
    		pm.subject = e.subject
    	end if
    	
    	'	e.message		C	=	The body of a text message. THIS WILL OVERRIDE emailNum.
    	if eval_valid("e.message") then
    		pm.message = e.message
    	end if
    	
    	'	e.html_message	C	=	The body of a HTML message. THIS WILL OVERRIDE emailNum.
    	if eval_valid("e.html_message") then
    		pm.html_message = e.html_message
    	end if
    	
    	'	e.attachments	C	=	A semi-colon (;), comma, or CR-LF delimited list of filenames.
    	if eval_valid("e.attachments") then
    		pm.attachments = e.attachments
    	end if
    	
    	' pm.xmailer is the sending email program name
    	pm.xmailer = "DAZSER MGMT v11 http://www.dazser.net - Complaints? [email protected]"
    	
    	'	e.lrelated		L	=	Default = .F. Attachments are seperate files, .T. for Embedded
    	if eval_valid("e.lrelated") then
    		pm.lrelated = e.lrelated
    	end if
    	
    	'	e.returnreceipt	L	=	Default = .F. This will ask the sender for a read receipt.
    	if eval_valid("e.returnreceipt") then
    		pm.returnreceipt = e.returnreceipt
    	end if
    	
    	'Send the Email
    	flag = email_smtp_open(ps, smtp_server, port, username, password)
    	if flag = .f. then
    		q.result = .F.
    		q.resultText = ps.buffer
    		sendEmail = q
    	    end
    	end if
    	
    	flag = email_smtp_send(pm, ps, .t.)
    	if flag = .f. then
    		q.result = .F.
    		q.resultText = ps.buffer
    		sendEmail = q
    		end
    	end if
    	
    	q.resultText = ps.buffer
    
    	flag = email_smtp_close(ps)
    	if flag = .f. then
       		q.result = .F.
    		q.resultText = "Email sent, but failed closing the connection."
    		sendEmail = q
    		end
    	end if
    	
    	q.result = .T.
    
    	sendEmail = q	
    	
    END FUNCTION
    Basically, I've got a table in my database with some 'template' emails. Here's an example:
    Code:
    (This is the html_msg for the email)
    
    
    <html>
    <head> </head>
    <body>
    <font face=Arial size=2>Dear {prospectname}, <br>Thanks for requesting information! 
    <p>What makes Jani-King clients renew their contracts year after year? Franchise Owners who have a vested interest to see that your facility is serviced correctly. 
    <a href="http://www.dazser.com/pdf/Trust.Your.Keys.Folder.pdf">Click Here</a> for more information.</p>
    <hr /><p>{sendername}<br />{senderemail}</p>
    </body>
    </html>
    Then I pass in a pointer with those variables included in curly braces.
    e.variables.prospectname
    e.variables.sendername
    etc...

    This little bit of code does the merging:
    Code:
    html_msg = evaluate_string(html_msg, e.variables)

    Comment


      #3
      Re: HTML Mail Script - Can Field Variable Values be included

      Thank you for your repply.

      Regards
      Tasos

      Comment

      Working...
      X