Solved

vbCrLf giving problems in ASP

Posted on 2006-07-14
14
314 Views
Last Modified: 2012-06-21
Hi,

This is the function i am using for sending mails.
I want to send this contents in mail in asp.

Address is
subject = "Camp Scholarship Application"
sbody = " Camp Education Program testing and the funding to be manipulated " & vbCrlf & _
             " Te Undergraduate Application " & vbCrlf  
sendmail "test@xyz.com","test@xyz.com","admin@xyz.com",subject,sbody,"T"

the email code i used is
function SendMail(aToAddress, aCC, aFromAddress, aSubj, aText, aFormat)
 
   dim Mail
   set Mail = Server.CreateObject("CDONTS.NewMail")

   'fill email fields
   Mail.From = aFromAddress    'To and From addresses must be in        
   Mail.To = aToAddress      'valid "user@domain.com" format
   Mail.CC = aCC
   Mail.Subject = aSubj
   Mail.Body = aText

   if aFormat = "H" then
         Mail.BodyFormat = 0        '0=HTML, 1=Text
         Mail.MailFormat = 0        '0=MIME, 1=Text
   else
         Mail.BodyFormat = 1        '0=HTML, 1=Text
         Mail.MailFormat = 1        '0=MIME, 1=Text
   end if

   Mail.Send        'email this message

   set Mail = Nothing        'free the message object
   SendMail = true
end function

email gets sent but the the formatting changes.
the email i get is simply a text messsage without any formatting. Something like this.
" Camp Education Program testing and the funding to be manipulated Te Undergraduate Application "
hwo can we make this working?

RD.
0
Comment
Question by:ck_damu
  • 6
  • 3
  • 2
14 Comments
 
LVL 12

Expert Comment

by:Preece
ID: 17111307
Shouldn't this call:

sendmail "test@xyz.com","test@xyz.com","admin@xyz.com",subject,sbody,"T"

be passing an H instead of a T?

sendmail "test@xyz.com","test@xyz.com","admin@xyz.com",subject,sbody,"H"

Preece
0
 
LVL 12

Accepted Solution

by:
Preece earned 125 total points
ID: 17111349
I think I see what you mean now.  Try this:

sbody = " Camp Education Program testing and the funding to be manipulated "
sbody = sbody & vbCrLf & " The Undergraduate Application " & vbCrLf

If you go with HTML format, try:

sbody = " Camp Education Program testing and the funding to be manipulated "
sbody = sbody & "<br>" & " The Undergraduate Application " & "<br>"


Preece
0
 
LVL 25

Expert Comment

by:kevp75
ID: 17111425
Preece is correct, you are trying to put in textual carriage breaks, when you are sending an html email

once you change them to the <br>'s you should be all set
0
 
LVL 1

Author Comment

by:ck_damu
ID: 17111509
HTML format works but Text format is giving problems, formatting is not working.
if you reduce the contents in sbody
i.e
sbody = " Camp Education Program"
sbody = sbody & vbCrLf & " The Undergraduate Application " & vbCrLf

This works, donno why?
RD
0
 
LVL 25

Assisted Solution

by:kevp75
kevp75 earned 125 total points
ID: 17111581
it's because of aFormat

you see in your code:
if aFormat = "H"

well...you are allowing the user to specify whether or not to send an HTML email or TEXT.  If they specify TEXT then your code above it will work perfectly, however when they change it to HTML it fails...why, because you do not have any conditioning in you sbody to change it from TEXT to HTML

the only way what you are trying will work is if you use a condition on your sbody, so

if aFormat = "H" then
     sbody = " Camp Education Program testing and the funding to be manipulated <br>"  & _
             " Te Undergraduate Application <br>"
else
     sbody = " Camp Education Program testing and the funding to be manipulated " & vbCrlf & _
             " Te Undergraduate Application " & vbCrlf
end if
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 12

Expert Comment

by:Preece
ID: 17111592
So, you are building your sbody and making the correctly in both scenarios?  Such as:

sbody = " Camp Education Program"
sbody = sbody & vbCrLf & " The Undergraduate Application " & vbCrLf
sendmail "test@xyz.com","test@xyz.com","admin@xyz.com",subject,sbody,"T"


sbody = " Camp Education Program"
sbody = sbody & "<br>" & " The Undergraduate Application " & "<br>"
sendmail "test@xyz.com","test@xyz.com","admin@xyz.com",subject,sbody,"H"

I wonder if it has anything to do with the Mail.MailFormat setting?

Preece
0
 
LVL 1

Author Comment

by:ck_damu
ID: 17111641
Try the below two code segment you can find the difference

1)
sbody = " Camp Education Program"
sbody = sbody & vbCrLf & " The Undergraduate Application " & vbCrLf
sendmail "test@xyz.com","test@xyz.com","admin@xyz.com",subject,sbody,"T"

2)
sbody = " Camp Education Program testing and the funding to be manipulated "
sbody = sbody & vbCrLf & " Te Undergraduate Application " & vbCrlf  
sendmail "test@xyz.com","test@xyz.com","admin@xyz.com",subject,sbody,"T"

RD
0
 
LVL 12

Expert Comment

by:Preece
ID: 17111645
kevp75 is correct.  Be sure to be consistent with your sbody formatting and your sendmail calling parameters.  

Another option might to use CDO instead of CDONTS, if your server supports it:

subject = "Camp Scholarship Application"
if strFormat = "T" then
    sbody = " Camp Education Program"
    sbody = sbody & vbCrLf & " The Undergraduate Application " & vbCrLf
    sendmail "test@xyz.com","test@xyz.com","admin@xyz.com",subject,sbody,"T"
else if strFormat = "H" then
    sbody = " Camp Education Program"
    sbody = sbody & "<br>" & " The Undergraduate Application " & "<br>"
    sendmail "test@xyz.com","test@xyz.com","admin@xyz.com",subject,sbody,"H"
end if

function gsnSendMail(aToAddress, aCC, aFromAddress, aSubj, aText, aFormat))
    Dim myMail
    Set myMail = Server.CreateObject("CDO.Message")      
    myMail.From = aFromAddress
    myMail.To = aToAddress
    myMail.CC = aCC
    'myMail.BCC = aBCC
    myMail.Subject = aSubj
    if aFormat = "H" then
        myMail.HtmlBody = aText
    else if aFormat = "T" then
        myMail.TextBody = aText
    end if
    myMail.Send
    Set myMail = Nothing
end function

Preece
0
 
LVL 12

Expert Comment

by:Preece
ID: 17111661
Also, don't forget the h in"

" Te Undergraduate Application "

Preece
0
 
LVL 12

Expert Comment

by:Preece
ID: 17111675
oops, a couple of typos:

Another option might to use CDO instead of CDONTS, if your server supports it:

subject = "Camp Scholarship Application"
if strFormat = "T" then
    sbody = " Camp Education Program"
    sbody = sbody & vbCrLf & " The Undergraduate Application " & vbCrLf
    gsnSendMail "test@xyz.com","test@xyz.com","admin@xyz.com",subject,sbody,"T"
else if strFormat = "H" then
    sbody = " Camp Education Program"
    sbody = sbody & "<br>" & " The Undergraduate Application " & "<br>"
    gsnSendMail "test@xyz.com","test@xyz.com","admin@xyz.com",subject,sbody,"H"
end if

function gsnSendMail(aToAddress, aCC, aFromAddress, aSubj, aText, aFormat)
    Dim myMail
    Set myMail = Server.CreateObject("CDO.Message")      
    myMail.From = aFromAddress
    myMail.To = aToAddress
    myMail.CC = aCC
    'myMail.BCC = aBCC
    myMail.Subject = aSubj
    if aFormat = "H" then
        myMail.HtmlBody = aText
    else if aFormat = "T" then
        myMail.TextBody = aText
    end if
    myMail.Send
    Set myMail = Nothing
end function

Preece
0
 
LVL 25

Expert Comment

by:kevp75
ID: 17314459
i'd like to know the outcome....
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now