BBC BASIC for Windows
Programming >> Communication and Input/Output >> SMTP
http://bb4w.conforums.com/index.cgi?board=communication&action=display&num=1350649804

SMTP
Post by Nanne on Oct 19th, 2012, 12:30pm

Hi there,

I am using the socklib library. I made a program to get the statistics from an IRC chatlog.

The output is:

Chatter1_________5 lines
Chattername2_____8 lines

Where _ is a space!

And so on.

I put the output in a variable body$:

body$=body$+chatter$(x%)+STRING$(20-LEN (chatter$(x%))," ")+lin$+CHR$13+CHR$10

So there a more space between the chattername and the amount of lines.

If I do PRINT body$ it looks fine!

When I send it using socklib library I get a mail with the output but the spaces are gone:

The output is:

Chatter1 5 lines
Chattername2 8 lines

Where are my spaces which I created with STRING$?

If I replace the spaces with "_" it works fine but I don't want "_", I want " " in the output.

Is there a solution for this?

Thank you,

Nanne



Re: SMTP
Post by admin on Oct 19th, 2012, 2:26pm

on Oct 19th, 2012, 12:30pm, Nanne wrote:
Where are my spaces which I created with STRING$?

Nothing in SOCKLIB removes spaces! You can look at the code yourself to confirm that. If you are using FN_writelinesocket() the entire string is passed to FN_writesocket() and thence to send. If you write a simple loop-back test, passing strings via sockets, multiple spaces are preserved.

Are you sure the problem isn't in the email client that you are using to view the received message? Some viewers automatically reduce multiple spaces to one space (for example Yahoo Groups does that, unless you select the 'fixed pitch font' option).

Richard.
Re: SMTP
Post by Nanne on Oct 19th, 2012, 4:28pm

Hi Richard,

You are completly right. The library itself doesn't remove spaces. It is the email client. In this case gmail.com and hotmail.com. Gmail.com says that the mail is may be spam and hotmail.com accepted it.
The only problem is that the remove spaces. I asked my question here because I cannot find a solution on the net. So maybe other users have the same problem and perhaps they have a solution.

Nanne
Re: SMTP
Post by admin on Oct 19th, 2012, 9:29pm

on Oct 19th, 2012, 4:28pm, Nanne wrote:
So maybe other users have the same problem and perhaps they have a solution.

You could try using non-break spaces (ANSI code 160 decimal / &A0 hexadecimal / HTML  ); it's possible that the email clients won't remove those. The only thing to watch is that strictly you may need to include a MIME header in the email to specify that you're using a non-ASCII character encoding.

Richard.
Re: SMTP
Post by Nanne on Oct 19th, 2012, 11:19pm

Hi Richard,

It works with CHR$160.

Thank you for this solution!

Nanne
Re: SMTP
Post by Nanne on Oct 23rd, 2012, 10:44pm

Is it possible to send a file using the socklib library. And If so how I have to do that?

I tried:

IF FN_writelinesocket(skt%, "Attach: "+"test.txt")

But it didn't work.

Nanne
Re: SMTP
Post by admin on Oct 24th, 2012, 08:20am

on Oct 23rd, 2012, 10:44pm, Nanne wrote:
Is it possible to send a file using the socklib library.

I assume from the context that you are referring to attaching a file to an email (rather than uploading it to an FTP server, for example). Is that right?

If an FTP upload is acceptable then this article tells you how to do it: http://bb4w.wikispaces.com/Uploading+files+to+an+FTP+server

Richard.
Re: SMTP
Post by Nanne on Oct 24th, 2012, 09:20am

Hi Richard,

Sorry, I was not clear in my question.

I want to attach a file (PDF) with my email-message.

I have read the documentation about FTP but my users (the receivers) can't use FTP sad So I have to attach a file to a message.

So, my question is: Is it possible to attach af file with using the socklib library?

Thank you,

Nanne
Re: SMTP
Post by admin on Oct 24th, 2012, 09:43am

on Oct 24th, 2012, 09:20am, Nanne wrote:
Is it possible to attach af file with using the socklib library?

Certainly it is "possible", but I'm not aware of anybody having done it before. You would need to create a multipart MIME email including the attachment, suitably encoded (e.g. as 'base64'). There is some useful information on what is needed here:

http://www.codeguru.com/cpp/i-n/internet/email/article.php/c3405/EMail-File-Attachments-Using-MIME.htm

At a quick glance it looks quite easy. Let us know how you get on (and ideally write a Wiki article - or even a BB4W library - for the benefit of others).

Richard.
Re: SMTP
Post by admin on Oct 24th, 2012, 5:30pm

on Oct 24th, 2012, 09:43am, Richard Russell wrote:
At a quick glance it looks quite easy.

In fact so easy I couldn't think of a good reason not to write it myself - so I did:

http://bb4w.wikispaces.com/Sending+an+email+with+attachments

It hasn't been extensively tested but appears to work. Let me know if you have any problems with it.

Richard.
Re: SMTP
Post by Nanne on Oct 24th, 2012, 11:12pm

Hi Richard,

Thank you for your work!

I'll try it this week and let you know if I have problems with it. When it works fine, which I assume, I let you know that too smiley

Nanne