using commas in the body of the SMTPSendMail command

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
howl
Junior Coder
Posts: 24
Joined: Tue May 29, 2007 6:41 pm

using commas in the body of the SMTPSendMail command

Post by howl » Mon Sep 17, 2007 8:54 pm

I'm using a variable for the body in the SMTPSendMail command. There are commas in the string and everything after the first comma gets cut off. How can I keep the commas? Example:

Let>bigbody=Please send me $1,500,000 in cash
SMTPSendMail>To,Server,FromAddress,FromName,Subject,bigbody

The body of the email ends up like this:

Please send me $1

Thanks in advance for your help.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Sep 17, 2007 9:03 pm

You've missed off the last parameter - attachments. You need a final comma (followed by nothing as you have no attachments):

Let>bigbody=Please send me $1,500,000 in cash
SMTPSendMail>To,Server,FromAddress,FromName,Subject,bigbody,

That works.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

While the example given works, it is not a complete solution

Post by mightycpa » Sun Mar 25, 2018 7:48 pm

I'm trying to send some email, and I'm getting thwarted by commas in the body too. I'm able to get the example in the answer above to work, but when it gets more complicated than that, it doesn't work.

This is mission-critical. How do I fix it?

Code: Select all

//MessageModal>This macro demonstrates how to send Email & Files using the SMTPSendMail command.
Let>SENDMAIL_STATUS=1
Let>SMTP_HTMLBODY=1

Let>SMTP_SSL=1
Let>SMTP_AUTH=1
Let>SMTP_USERID=**************
Let>SMTP_PASSWORD=********

LabelToVar>Welcome0,msg0

/*
Welcome0:
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1   {color: blue;}
p    {color: red;}

a.button2{
 display:inline-block;
 padding:0.5em 3em;
 border:0.16em solid #FFFFFF;
 margin:0 0.3em 0.3em 0;
 box-sizing: border-box;
 text-decoration:none;
 text-transform:uppercase;
 font-family:'Roboto',sans-serif;   /* <------ this comma right here is what cuts off the message  */
 font-weight:400;
 color:#FFFFFF;
 text-align:center;
 transition: all 0.15s;
}
a.button2:hover{
 color:#DDDDDD;
 border-color:#DDDDDD;
}
a.button2:active{
 color:#BBBBBB;
 border-color:#BBBBBB;
}
@media all and (max-width:30em){
 a.button2{
  display:block;
  margin:0.4em auto;
 }
} 

</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>

<a href="something" class="button2">Button</a>
<a href="something" class="button2">Very pretentious long button</a>	

Oh, and a comma will fail down here too.

</body></html>


*/

//MessageModal>msg
//GoTo>end
 
Let>smtp=smtp.gmail.com
Let>fromname=********
Let>fromemail=**********
Let>toemail=************
Let>subject=Comma Trouble!

SMTPSendMail>toemail,smtp,fromemail,fromname,subject,%msg0%,
//MessageModal>SMTP_RESULT
MidStr>SMTP_RESULT,1,3,ErrCode
If>%ErrCode%=250
  //Do Nothing
Endif

Label>end

"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: using commas in the body of the SMTPSendMail command

Post by Marcus Tettmar » Sun Mar 25, 2018 9:32 pm

Remove the % signs from msg0. You're not embedding anything there. The variable should be on it's own:

SMTPSendMail>toemail,smtp,fromemail,fromname,subject,msg0,
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: using commas in the body of the SMTPSendMail command

Post by mightycpa » Mon Mar 26, 2018 4:37 am

Yes, that seems to have worked, thank you. I'm not sure I understand why this is necessary.

This line is from your example code:

Code: Select all

SMTPSendMail>toemail,smtp,fromemail,fromemail,subject,%msg%,attach
Is this variable embedded? I don't quite understand the difference.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: using commas in the body of the SMTPSendMail command

Post by Marcus Tettmar » Mon Mar 26, 2018 8:42 am

You're right, it shouldn't make a difference and I'm looking into that now. However, when referencing a variable on its own my rule of thumb is not to use % symbols. I only use them if I want to reference the variable within another string.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts