Posts Tagged ‘ActionScript 3’

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.

The sample code for google gmail buzz using airxmail ( as3 smtp/pop library)

google_buzz

sender = new SMTPSender();
sender.setParameter(SMTPSender.HOST,"smtp.gmail.com");
sender.setParameter(SMTPSender.PORT,465);

//  use SMTP-AUTH
sender.setParameter(SMTPSender.AUTH,true);
sender.setParameter(SMTPSender.USERNAME,username);
sender.setParameter(SMTPSender.PASSWORD,password);

// use STARTTLS
sender.setParameter(SMTPSender.SOCKET_OBJECT,new com.hurlant.crypto.tls.TLSSocket());

// If you want to change the charset for mail header
AirxMailConfig.setDefaultHeaderCharset("UTF-8");
			
var mimeMsg:MimeMessage = new MimeMessage();
			
var from:INetAddress = new INetAddress();
from.personal = "coltware";
from.address = this.fromEmail;
			
mimeMsg.setFrom(from);
var toAddr:INetAddress = new INetAddress("buzz@gmail.com","buzz");
mimeMsg.addRcpt(RecipientType.TO,toAddr);
// set mail subject
mimeMsg.setSubject("My first buzz from airxmail");
mimeMsg.setTextBody("");

sender.send(mimeMsg);
sender.close();
RSS
Add to Google
2017年3月
« 2月    
 1234
567891011
12131415161718
19202122232425
262728293031