Posts Tagged ‘smtp’

I updated Gravity Mail.
This version features is “Tag” based management messages.

I want to make e-mail client application like my blog site using e-mail for my private purposes.
This page is Gravity Mail information page in Japanese.
But some images help you to understand it. I hope….

I am making e-mail client application using Adobe AIR.
Please see the details.

But this application is in development.

The STARTTLS extension is complex for a moment.
A smtp client have to connect the server with plain socket.
After the client gives STARTTLS command , the client have to change to tls socket from plain socket.

The following code is a sample to use STARTTLS command


// comment out because of using plain socket
//sender.setParameter(SMTPSender.SOCKET_OBJECT,new TLSSocket());

sender.addEventListener(SMTPEvent.SMTP_START_TLS,startTlsHandler);

// chage to TLSSocket
public function startTlsHandler(event:SMTPEvent):void{
var sock:Object = event.socket as Socket;
var tls:TLSSocket = new TLSSocket();
sender.setParameter(SMTPSender.SOCKET_OBJECT,tls);

tls.startTLS(sock,”your.host.name”); // <– please set “your.host.name” as you like } [/as3]

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

var from:INetAddress = new INetAddress();
from.personal = 
from.address = "from.email.address@coltware.com";


mimeMsg.setFrom(from);
mimeMsg.setReplyTo(from);
var toAddr:INetAddress = new INetAddress("to.email.address@coltware.com","hello airxmail");
mimeMsg.addRcpt(RecipientType.TO,toAddr);
// set mail subject
mimeMsg.setSubject("Hello World"); 
mimeMsg.setTextBody("this is multipart message");  

//
//  Plain Text Part
//
var textPart:MimeTextPart = new MimeTextPart();
textPart.contentType.setParameter("charset","UTF-8");
textPart.transferEncoding = "8bit";
textPart.setText("This is text body part \n This is 2nd line.");
mimeMsg.addChildPart(textPart);

//
//  Attachment part 
//
var filePart:MimeImagePart = new MimeImagePart();
filePart.contentType.setMainType("image");
filePart.contentType.setSubType("jpeg");
filePart.setAttachementFile(File.desktopDirectory.resolvePath("image.jpg"),"fireworks.jpg");
mimeMsg.addChildPart(filePart);

This is a sample code to send email attachments 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
How to send html mail.

sample code

use MimeBinaryPart ( application/octet-stream )

basic usage
var contentType:ContentType = ContentType.MULTIPART_MIXED;
var mimeMsg:MimeMessage = new MimeMessage(contentType);
:
:
var filePart:MimeBinaryPart = new MimeBinaryPart();
filePart.setAttachementFile(File.desktopDirectory.resolvePath("image.jpg"),"attachemnt-image.jpg");
mimeMsg.addChildPart(filePart);

sender.send(mimeMsg);
sender.close();
how to change content-type
var filePart:MimeBinaryPart = new MimeBinaryPart()
filePart.contentType.setMainType("image");
filePart.contentType.setSubType("jpeg");

Note: MimeImagePart is image/xxxx part.

filePart:MimeImagePart = new MimeImagePart();
filePart.setAttachementFile(file,"attachemnt-image.jpg");   // --> image/jpeg
//filePart.setAttachementFile(file,"attachemnt-image.gif");   // --> image/gif

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