Home > Class Reference > ENSLIB namespace > %Net.FetchMailProtocol


abstract class %Net.FetchMailProtocol extends %Library.RegisteredObject

Abstract Class that %Net.POP3 implements.

Methods are Connect,(),GetMailBoxStatus(), GetSizeOfMessages(),GetMessageUIDArray(), FetchMessage(),DeleteMessage(), RollbackDeletes(),QuitAndCommit(), QuitAndRollback(),Ping().

Important after Connect() is called, you must call before your session ends either QuitAndCommit() or QuitAndRollback().

Each of the methods of this class returns a value of type %Status indicating success or failure.

The charset used for each text mail message part is returned in the Charset property of the %Net.MailMessagePart class. The data is automatically translated to the current cache locale's default character set when reading from the TextData text stream.

The following shows an example of getting messages:

  #include %occOptions
  #include %occStatus
  ; display mail but don't delete from mailbox
  testmail6 ;
  new mailserver,status,err,mailMsg
  set mailserver=##class(%Net.POP3).%New()
  set mailserver.AttachDir="d:\attach\"  ; need terminating \
  set mailserver.StoreAttachToFile=1
  write !,"Calling Connect"
  set status=mailserver.Connect("moon.kinich.com","testjsl","jsltest")
  if $$$ISERR(status) do DecomposeStatus^%apiOBJ(status,.err) write !,err(err),! quit
  write !,"Calling Fetch to retrieve the oldest message on the server."
  set status=mailserver.Fetch(1,.mailMsg,0)
  if $$$ISERR(status) do DecomposeStatus^%apiOBJ(status,.err) write !,err(err),! quit
  write !,"from="_mailMsg.From
  write !,"to="_mailMsg.Headers.GetAt("to")
  write !,"date="_mailMsg.Date
  write !,"subject="_mailMsg.Subject
  write !,"messagesize="_mailMsg.MessageSize
  do DumpMessage(mailMsg)
  new i,index,value,len
  if msg.IsMultiPart {
      for i=1:1:msg.Parts.Count() write !,"Dumping part "_i do DumpMessage(msg.Parts.GetAt(i))
  set index=""  for  set value=msg.Headers.GetNext(.index) quit:index=""  write !,"Headers("_index_")="_value
  if msg.IsBinary {
      write !,"msg is binary, filename="_msg.FileName_" filename="_msg.GetAttribute("content-disposition","filename")
  } else {
      write !,"Dumping text msg Filename="_msg.FileName_" filename="_msg.GetAttribute("content-disposition","filename"),!
      set stream=msg.TextData
      do stream.Rewind()
      set len=32763
      while 'stream.AtEnd {
          write stream.Read(.len)

Property Inventory (Including Private)

Method Inventory (Including Private)

Properties (Including Private)

property AttachDir as %String;
When receiving messages using POP3, the directory where attached files will be stored
Property methods: AttachDirDisplayToLogical(), AttachDirGet(), AttachDirIsValid(), AttachDirLogicalToDisplay(), AttachDirLogicalToOdbc(), AttachDirNormalize(), AttachDirSet()
property Connected as %Boolean;
Property methods: ConnectedDisplayToLogical(), ConnectedGet(), ConnectedIsValid(), ConnectedLogicalToDisplay(), ConnectedNormalize(), ConnectedSet()
property Debug as %Integer [ InitialExpression = 0 ];
Property methods: DebugDisplayToLogical(), DebugGet(), DebugIsValid(), DebugLogicalToDisplay(), DebugNormalize(), DebugSet()
property StoreAttachToFile as %Integer [ InitialExpression = 0 ];
We always store attachments as a part in the message. If StoreAttachToFile=true and content-disposition MIME header of attachment part = "attachment", we ALSO store to the directory specified in AttachDir
Property methods: StoreAttachToFileDisplayToLogical(), StoreAttachToFileGet(), StoreAttachToFileIsValid(), StoreAttachToFileLogicalToDisplay(), StoreAttachToFileNormalize(), StoreAttachToFileSet()
property StoreInlineToFile as %Integer [ InitialExpression = 0 ];
We always store attachments as a part in the message. If StoreInlineToFile=true and content-disposition MIME header of attachment part = "inline", we ALSO store to the directory specified in AttachDir
Property methods: StoreInlineToFileDisplayToLogical(), StoreInlineToFileGet(), StoreInlineToFileIsValid(), StoreInlineToFileLogicalToDisplay(), StoreInlineToFileNormalize(), StoreInlineToFileSet()

Methods (Including Private)

method %OnClose() as %Status

Protect against terminating without doing a quit

method Connect(PopServer As %String, UserName As %String, Password As %String) as %Status

Use to logon to your mail server using the username and password that are the parameters to this routine.

method DeleteMessage(MessageNumber As %Integer) as %Status

This method deletes a single message. MessageNumber must be a valid message number and the message must not be currently marked for deletion.

method Fetch(MessageNumber As %Integer, ByRef Msg As %Net.MailMessage, Delete As %Boolean, messageStream As %BinaryStream) as