SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Asp sending email with UTF-8

  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    South Russia/UK
    Posts
    723
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Asp sending email with UTF-8

    Hello,

    I think I gave up after I spent a whole day figuring this out, so Im here for help

    Im using ASPEmail to send emails from asp page. The message body content comes from an application variable like this:

    Code:
    objMail.Body = GetLang("regWelcome") .. etc
    The thing is, if I use Request.Form like this:

    Code:
    objMail.Body = Request.Form ("regWelcome") .. etc
    it comes fine, but with pulling a value from application variable it doesnt work. At the same time on a page with UTF-8 encoding(<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />) the

    Code:
    GetLang("regWelcome")
    prints fine.

    Any clue what am I doing wrong?

    I read on persits website:

    9. If you are building Mail.Body using string variables that are populated from a source such as a database, ensure that they contain valid data. Ensure that your data is not encoded already, as it will come out garbled if AspEmail re-encodes already-encoded data.
    Probably thats the problem? But what is a solution?

    p.s: same thing happens with microsoft's CDO component.

  2. #2
    SitePoint Member Kul-Tigin's Avatar
    Join Date
    Aug 2011
    Location
    Turkey
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. ASP File must encoded in UTF-8.
      If you don't have any idea about it: saving files in utf-8 - Google Search
    2. Define a CodePage directive on your asp file like this (it must be a parent file, not included etc.):
      Code ASP:
      <%@Language = VBScript Codepage = 65001 %>
      <%
      'Your codes starts
      '..
      '..
      %>
      65001 defines ASP CodePage property is UTF-8 (required for integrated ASP objects)
    3. Finally, you can use AspEmail's Charset property for usual charset invasions.
      For Thai Language :
      Code ASP:
      your_aspemail_object.Charset = "windows-874"
      More information: AspEmail.com - Object Reference

    Try them.

  3. #3
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    South Russia/UK
    Posts
    723
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kul-Tigin, thanks for reply , but i tried all that, all this works only if .body content is coming from Request.Form like in the example of ASPemail unicode demo.

    if we try to put into .body Application("variable") (in utf characters) it doesnt work and the email comes as garbage.

    anyways, I guess its a blackhole in asp unicode email sending.

  4. #4
    SitePoint Member Kul-Tigin's Avatar
    Join Date
    Aug 2011
    Location
    Turkey
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you give me a sample file (uses Application Variable). I would like investigate.

  5. #5
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    South Russia/UK
    Posts
    723
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check pm

  6. #6
    SitePoint Member Kul-Tigin's Avatar
    Join Date
    Aug 2011
    Location
    Turkey
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Click to attach icon on toolbar while replying and upload your file.
    If code is private, you can send me via e-mail : reCAPTCHA Mailhide: Free Spam Protection

  7. #7
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    South Russia/UK
    Posts
    723
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i sent via free hosting, check link in pm

  8. #8
    SitePoint Member Kul-Tigin's Avatar
    Join Date
    Aug 2011
    Location
    Turkey
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi again.
    You should use Adodb.Stream instead of FSO.
    Problem is not from application variables. FSO doesn't support utf-8.
    Try the following procedure named "LanguageConvertFile":

    Code ASP:
    'read language file
    sub LanguageConvertFile (strfilename, fieldnames,fieldvalues, fieldcount)
       dim rc, whichfile, adoStream, pos_equal, record, fieldname, fieldvalue
       fieldcount=0
    	on error resume next
       whichfile=server.mappath(strfilename)
       set adoStream = Server.CreateObject("Adodb.Stream")
    	adoStream.Open
    	adoStream.Charset = "UTF-8"
    	on error resume next
    	adoStream.LoadFromFile whichfile
       if err.number > 0 then
             adoStream.Close
             set adoStream = Nothing
             exit sub
       end if
       do while not adoStream.EOS
                record = trim(adoStream.ReadText(-2))
                pos_equal = instr(record,"=")
    		if pos_equal <> 0 then
                fieldname = mid(record,1,pos_equal-1)
    			rc = len(record) - pos_equal
                fieldvalue = mid(record,pos_equal+2,rc-2)			
                fieldnames(fieldcount)=fieldname
                fieldvalues(fieldcount)=fieldvalue
                fieldcount=fieldcount+1
    	    end if
       loop
       adoStream.Close
       set adoStream = nothing
    end sub

  9. #9
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    South Russia/UK
    Posts
    723
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot man! Now it works.

    and assalamu aleikum!

    so Adodb.Stream is the same as FSO but with utf support?

  10. #10
    SitePoint Member Kul-Tigin's Avatar
    Join Date
    Aug 2011
    Location
    Turkey
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aleyküm selam

    Not exactly same but some times Stream object may be required.
    Actually FSO is for file system operations and it's not enough for advanced stream / text operations.
    So, using an Adodb.Stream object make more sence.
    DevGuru is a good resource for all ADO interfaces, i recommend it.
    DevGuru ADO Stream Object

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •