0

i want to send email using html code. plzz help

GMailSender m = new GMailSender("", "");

    String[] toArr = {""};
    m.setTo(toArr); // load array to setTo function
    m.setFrom("dawinderg@gmail.com"); // who is sending the email 
    m.setSubject("Registration"); 
    m.setBody("Thanks for registration with us.");

i want to send

+username+

this code in m.setBody(). how can i do this??

1 Answers1

0

You can use this:

m.setBody(Html.fromHtml("<h1>Title</h1><br>Username "+ username +" and password"));

You can also create html tables or any other html elements

If the example is from here: GMailSender example

Change

DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));

withDataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/html"));

and add the body like this:

m.setBody("<html><h1>TESTING<h1></html>");
Community
  • 1
  • 1
MSA
  • 2,502
  • 2
  • 22
  • 35
  • if i use this then this shows error. because my setBody function having return type String. – Dawinder Gill Aug 28 '14 at 11:58
  • 2 min I will return with example :) – MSA Aug 28 '14 at 12:07
  • I search a bit before I start the demo project and 1 question for you: Are you using the class example in this link: http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a If yes the solution is simple:) – MSA Aug 28 '14 at 12:22
  • ohk thxxx alot here is my setbody and get body function public String getBody() { return _body; } public void setBody(String _body) { this._body = _body; } – Dawinder Gill Aug 28 '14 at 12:24
  • here is my send function MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(_from)); InternetAddress[] addressTo = new InternetAddress[_to.length]; for (int i = 0; i < _to.length; i++) { addressTo[i] = new InternetAddress(_to[i]); } msg.setRecipients(MimeMessage.RecipientType.TO, addressTo); msg.setSubject(_subject); msg.setSentDate(new Date()); BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(_body); _multipart.addBodyPart(messageBodyPart); msg.setContent(_multipart); Transport.send(msg); – Dawinder Gill Aug 28 '14 at 12:26
  • yes the string there is ok but you need to change the encoding type: until now it was "text/plain" you need to change it to "text/html" :) – MSA Aug 28 '14 at 12:27
  • u know how to attach printer with appto print the bill?? and how to upload image into database with json and show into the listview?? – Dawinder Gill Aug 29 '14 at 09:27
  • Well for the moment I will give you only some ref links: Json send image: http://geekonjava.blogspot.de/2014/03/upload-image-on-server-in-android-using.html. Oh and almost forgot if the answer was usefull +1 please or if the answer was what you where locking for please mark it as correct :). Thanks – MSA Aug 29 '14 at 10:14
  • If I will have time today I will try to make a simple app demo with your request from above(printer and json) cheers – MSA Aug 29 '14 at 10:15
  • bro one more help i need i have a project like whats app but i d'nt know how to start it and how it's working..... please help yr – Dawinder Gill Aug 30 '14 at 07:51
  • where are you bro??? is it possible that send image with img src tag of html in above email method?? – Dawinder Gill Sep 01 '14 at 05:12