Mail [examples]

Connect to the specified mail server
OPENMAIL
// Open POP3 for reading mail
m_open = openmail("mailserver.company.com", "username", "password", "POP3")
if not m_open
    dialog box mailerror()
endif
closemail()
 
// Open SMTP for sending
m_open = mailopen("mailserver.company.com")
if not m_open
    dialog box mailerror()
endif
closemail()

https://www.lianja.com/doc/index.php/OPENMAIL()


Read the specified mail message
READMAIL
number = readmail(1, "mail_mes", "BODY")
? number
        30
? mail_mes[30]
This is the last line in the mail message.

https://www.lianja.com/doc/index.php/READMAIL()


Send mail
SENDMAIL
// Open SMTP mail connection to the mail server
m_open = mailopen("mailserver.company.com","username","password","SMTP")
if not m_open
    dialog box mailerror()
    return
endif
 
// send the mail
fromname = "info@lianja.com"
tonames = "fred@lianja.com;sue@lianja.com"
ccnames = "bert@lianja.com;linda@lianja.com"
subject = "For your information"
msg = "Dear All" + chr(10) + "Here are the files you asked for.";
 + chr(10) + "Best regards" + chr(10) + "Sam"
attachments = "info.doc, info.xls"
mailsend(fromname, tonames, ccnames, subject, msg, attachments)
 
// close the connection to the mail server
mailclose()
 
// Open SMTP mail connection to the mail server
m_open = mailopen("mailserver.company.com", "username", "password")
if not m_open
    dialog box mailerror()
    return
endif
 
// sendmail() and mailsend() are functionally identical
fromname = "info@lianja.com"
tonames = "fred@lianja.com"
ccnames = ""
subject = "For your information"
msg = "email.htm"
attachments = ""
content = "text/html"
sendmail(fromname, tonames, ccnames, subject, msg, attachments, .F., content)
 
// close the connection to the mail server
mailclose()

https://www.lianja.com/doc/index.php/SENDMAIL()


Disconnect from mail server
CLOSEMAIL
closemail()

https://www.lianja.com/doc/index.php/CLOSEMAIL()


Number of messages on the currently connected mail server
COUNTMAIL
value = countmail(message_size)
? value
         6
? message_size[1]
       365

https://www.lianja.com/doc/index.php/COUNTMAIL()


Delete the specified mail message
DELETEMAIL
deletemail(1)

https://www.lianja.com/doc/index.php/DELETEMAIL()


Save a mail message attachment to a file
MAILATTACH
if mailattach(1, "mailattach.zip")
    ! unzip mailattach.zp
else
    ? "Mail attachment could not be saved."
endif

https://www.lianja.com/doc/index.php/MAILATTACH()


Disconnect from mail server
MAILCLOSE
mailclose()

https://www.lianja.com/doc/index.php/MAILCLOSE()


Number of messages on the currently connected mail server
MAILCOUNT
value = mailcount(message_size)
? value
         6
? message_size[1]
       365

https://www.lianja.com/doc/index.php/MAILCOUNT()


Delete the specified mail message


 

maildelete(1)

https://www.lianja.com/doc/index.php/MAILDELETE()


Last mail error

? mailopen("mailserver.company.com","username","password")
.F.
? mailerror()
Host name 'mailserver.company.com' not found.

https://www.lianja.com/doc/index.php/MAILERROR()


Return specified header information

number = mailread(1, "mail_mes")
? number
        30
? mailheader(mail_mes, "FROM")
sales@lianja.com

https://www.lianja.com/doc/index.php/MAILHEADER()


Node name of the currently connected mail server

? mailopen("mailserver.company.com","username","password")
.T.
? mailnodename()
mailserver.company.com

https://www.lianja.com/doc/index.php/MAILNODENAME()


Connect to the specified mail server

// Open POP3 for reading mail
m_open = mailopen("mailserver.company.com", "username", "password", "POP3")
if not m_open
    dialog box mailerror()
else
    // process mail
    mailclose()
endif
 
// Open SMTP for sending
m_open = mailopen("mailserver.company.com","username","password", "SMTP")
if not m_open
    dialog box mailerror()
else
    //process mail
    mailclose()
endif

https://www.lianja.com/doc/index.php/MAILOPEN()


Read the specified mail message

number = mailread(1, "mail_mes", "BODY")
? number
        30
? mail_mes[30]
This is the last line in the mail message.

https://www.lianja.com/doc/index.php/MAILREAD()


Save the body of a mail message to a file

if mailsaveas(1, "mailmes.txt")
    vi mailmes.txt
else
    ? "Mail message could not be saved."
endif

https://www.lianja.com/doc/index.php/MAILSAVEAS()


Send mail

// Open SMTP for sending
m_open = mailopen("mailserver.company.com","username","password","SMTP")
if not m_open
    dialog box mailerror()
    return
endif
 
fromname = "info@lianja.com"
tonames = "fred@lianja.com;sue@lianja.com"
ccnames = "bert@lianja.com;linda@lianja.com"
subject = "For your information"
message = "Dear All" + chr(10) + "Here are the files you asked for." + chr(10) + ;
"Best regards" + chr(10) + "Sam"
attachments = "info.doc, info.xls"
mailsend(fromname,tonames,ccnames,subject,message,attachments)
mailclose()
 
// Open SMTP for sending
m_open = mailopen("mailserver.company.com","username","password","SMTP")
if not m_open
    dialog box mailerror()
    return
endif
 
fromname = "info@lianja.com"
tonames = "fred@lianja.com"
ccnames = ""
subject = "For your information"
message = "email.htm"
attachments = ""
content = "text/html"
sendmail(fromname,tonames,ccnames,subject,message,attachments,.F.,content)
mailclose()

https://www.lianja.com/doc/index.php/MAILSEND()


Return current user name

? mailopen("mailserver.company.com","username","password")
.T.
? mailusername()
username

https://www.lianja.com/doc/index.php/MAILUSERNAME()


Advertisements