PDA

View Full Version : Receiving Mail only in the format of Plain Text Using QTcpSocket in SMTP



$ATHEES
4th September 2013, 08:52
I need to send a HTML files to Mail
i am using QTCPSocket ,
i don t Know how to separate the Header and the Body content

while i am sending without Header (from , to , subject), i can receive
in HTML format

when i add both and Header and content , i had received header correctly(from , to , subject) but ,
i not getting the HTMlL format
i am getting only in Text format

so plz give me some tips
thanks in advance

ChrisW67
4th September 2013, 09:42
All emails are just text. You want to send a MIME encoded body to carry an HTML email body if you want the receiving mail reader to treat it as HTML.
See RFC 2045 (http://www.ietf.org/rfc/rfc2045.txt) and RFC 2046 (http://www.ietf.org/rfc/rfc2046.txt).

$ATHEES
4th September 2013, 10:42
thanks for your suggestion..Guru
But
I had tried that ,
using that document only i had send a mail.
when i set a content type as HTML and Header name .
it also considering as Plain text
hear i attached my coding only the body content



Smtp::Smtp( const QString &from, const QString &to, const QString &subject , const QString &body ,const QString &address,int port)
{
socket = new QTcpSocket(this);
connect( socket, SIGNAL(readyRead()), this, SLOT( readyRead() ) );
connect( socket, SIGNAL( connected()), this, SLOT( connected() ) );
connect(socket, SIGNAL(disconnected()), this,SLOT(disconnected()));
message = "To: " + to + "\n";
message.append("From: " + from + "\n");
message.append("Subject: " + subject + "\n");
//Let's intitiate multipart MIME with cutting boundary "frontier"
message.append("MIME-Version: 1.0\n");
message.append("Content-Type: multipart/mixed; boundary=frontier\n\n");
message.append( "--frontier\n" );
//message.append( "Content-Type: text/html\n\n" ); //Uncomment this for HTML
formating, coment the line below
message.append( "Content-Type: text/html\n\n" );

message.append(body);

message.append("\n\n");
message.append( "--frontier--\n" );

message.replace( QString::fromLatin1( "\n" ), QString::fromLatin1( "\r\n" ) );

message.replace( QString::fromLatin1( "\r\n.\r\n" ),QString::fromLatin1( "\r\n..\r\n" ) );

this->from = from;
rcpt = to;
state = Init;
socket->connectToHost( address,port);//"172.17.72.36", 25);
t = new QTextStream( socket );
if(socket->waitForConnected ( 30000 ))
{qDebug("connected"); }
}

anda_skoa
4th September 2013, 10:44
Oh dear, extreme multiposting, going to merge threads.

Conflicting subjects too, but the postings seem to be the same.

$ATHEES
4th September 2013, 10:48
sorry ,
i not getting your answer
so Plz elobrate it.
give some correction in code
where i need to change

thanks in advance

anda_skoa
4th September 2013, 13:38
In case you are referring to me, I didn't comment on the question itself, just merged the duplicated threads into one.
You want all people to see all suggestions given so far, not a lot of duplicates all over the place.

Cheers,
_

$ATHEES
7th September 2013, 13:23
ok ...........thank you

ChrisW67
8th September 2013, 10:45
thanks for your suggestion..Guru
But
I had tried that ,

Now, you see, that would have been useful information to have in your first post. It would be useful to know how the bytes are actually sent, what an example non-functioning message looks like (i.e. the actual complete, constructed message), what bytes are actually being received, what you are using to determine "i not getting the HTMlL format", what is 'it' in "it also considering as Plain text" etc.

The boundary marker you have chosen is poor and could conceivably appear in the text of a part. Apart from that there is nothing that immediately jumps out as fundamentally broken with the code you posted. That code does not send, receive or interpret the received bytes though.