Posts Tagged ‘html mail’

This is a sample code to send html mail for airxmail(actionscript 3 smtp/pop3 library).

Requirements:
Flex SDK 3.4 or more
AIR 1.5 or more
airxmail library ( download )

related links:
Basic usage of airxmail

sample code

var contentType:ContentType = ContentType.MULTIPART_ALTERNATIVE;
var mimeMsg:MimeMessage = new MimeMessage(contentType);
			
var from:INetAddress = new INetAddress();
from.personal = "Sample User";
from.address = this.fromEmail;
			
mimeMsg.setFrom(from);
var toAddr:INetAddress = new INetAddress(this.toEmail,"Customer");
mimeMsg.addRcpt(RecipientType.TO,toAddr);
// set mail subject
mimeMsg.setSubject("this is first my message");
mimeMsg.setTextBody("this is multipart message");
			
// TextPart
var partText:MimeTextPart = mimeMsg.createTextPart();
partText.setText("this is plain body");
			
// HtmlPart
var partHtml:MimeTextPart = mimeMsg.createTextPart();
partHtml.setHtmlText("<html><body><b>THIS IS HTML BODY</b></body></html>");
			
sender.send(mimeMsg);
sender.close();

There are 3 points that you should care in the source code.

1. multipart message

var contentType:ContentType = ContentType.MULTIPART_ALTERNATIVE;
var mimeMsg:MimeMessage = new MimeMessage(contentType);

Default content type is ‘text/plain’.

2. make child part for text and html

var partText:MimeTextPart = mimeMsg.createTextPart();

3. set body text ( or html text )

MimeTextPart has 2 property to set the body text;

  • setText — set plain text(text/plain)
  • setHtmlText – set html text(text/html)

Next time: how to make e-mail with attachemnt files.

RSS
Add to Google
2017年1月
« 2月    
1234567
891011121314
15161718192021
22232425262728
293031