paul bennett

asp nuggets: send email and insert line feeds into email

Posted on: November 5, 2007

In case you find yourself (as I have on a recent project) delving into the seedy underbelly of a server-side you’re neither familiar with or particularly fond of (*cough*ASP*cough*), here’s a couple of gems which may help you out.

ASP has plenty of gotcha’s (as does any programming language to be sure) so here are solutions to a couple of my common problems.

Sending email

Actually pretty simple, but I can across a couple of different ways of doing it. This is the way that actually worked.

Set myMail=CreateObject("CDO.Message")
myMail.Subject="I de best"
myMail.From="webserver@mydomain.org.nz"
myMail.To="billy@johnsue.net"
myMail.TextBody="Behold! The email content!."
myMail.Send
set myMail=nothing

Inserting line feeds

In order to stop your email text from loking like the blancmange of doom, you’ll need to insert some line break / line feed characters. I spent an inordinate amount of time looking for how to achieve this. (Is there anything like php.net for asp? Some of the online ‘documentation’ leaves a lot to be desired…)

Return (VB ‘carriage return’):

myMessage = “hello.” & vbCr & “My name is Trevor”

Return and New Line (VB ‘carriage return and line feed’):

myMessage = “Hello, my name is Trevor” & vbCrLf & “What be your name?”

4 Responses to "asp nuggets: send email and insert line feeds into email"

This is very usefull, thanks!

Not even w3schools make any mention of this on their site under the asp mail section ->
http://www.w3schools.com/asp/asp_send_email.asp

Hi Everybody,

I have a problem similar to the one you showed.

I’m using “php” and trying to concatenate some variables to create the message on an email. But I would like to have a line feed to separate the data.

For example:

$message=’Client Name: ‘.$name.’Phone: ‘.$phone.’Fax: ‘.$fax;

I just need to know what code and how to include it in the instruction.

I’ll appreciate any help on this!

M@rko,

This should work:

$message=’Client Name: ‘.$name.”\r”
$message .= ’Phone: ‘.$phone..”\r”
$message .= ’Fax: ‘.$fax;

\r = carriage return
\n = new line

(you can use them in combination too)

🙂
Paul

It seems that just adding a “\n” in the string does the trick for me.

Leave a comment

Archives