|
Cookbook /
WikiMailSummary: Provide support for email for other recipes
Version: 2008-08-16
Prerequisites: 2.2.x beta
Status: Beta
Maintainer: Peter Bowers
Categories: DevelopmentTool
Download: wikimail.phpΔ
Questions answered by this recipe
DescriptionThis is a support recipe to provide a tool for other recipes. But if another recipe wants to read or write email then this "tool" will provide that capability without reinventing the wheel. Installation and configurationBegin with the usual, placing wikimail.phpΔ in your cookbook directory and placing this line in your config.php:
include_once("$FarmD/cookbook/wikimail.php");
Depending on how the recipe is configured which USES wikimail, you may or may not have to set these up. Generally it makes sense to give a sensible value to the ones that are emphasized as required/recommended. For SENDING mail you will want to set up some or all of these (host, user, and passwd are usually required, from is recommended): $WikiMailSMTP['Host'] // only used on win32 systems $WikiMailSMTP['User'] // user for SMTP $WikiMailSMTP['Passwd'] // passwd for SMTP $WikiMailSMTP['Port'] // only used on win32 systems - 0=default $WikiMailSMTP['SendmailPath']// only used on unix systems $WikiMailSMTP['From'] // must be set in config.php unless already set via php.ini For RECEIVING mail you will want to set up some or all of these (host, user, and pass are usually required):
# Simple example, setting up a profile named 'xyz' to access email for myuser@my.host.com using mypasswd as the password
wmMkProfilePOP3('xyz', 'my.host.com', 'myuser', 'mypasswd');
The rest of the (optional) parameters to MkProfilePOP3 are found in the following list:
PROFILE NAME // name of the profile - see the using recipe for instructions
host // POP3 server host name
user // Authentication user name
password // Authentication password
port // POP 3 server host port, usually 110
// but some servers use other ports. Gmail uses 995.
TLS // Establish secure connections using TLS
Realm // Authentication realm or domain
Workstation // Workstation for NTLM authentication
APOP // Use APOP authentication
AuthMech // SASL authentication mechanism
Debug // Output debug information
HTMLDebug // Debug information is in HTML
JoinHeader // Concatenate headers split in multiple lines
For any options where you are satisfied with the defaults simply pass the string "default". You can also change the defaults by calling NotesDevelopersIf you are a developer wanting to get mail capabilities (either sending or receiving) in your recipe, please see the comments internal to the PHP file for how to do this. Here is a quick smattering of some of those comments, copied verbatim (from the 2008-08-16 version):
# // (The wmMkProfilePOP3 call will often be done in config.php - note that
# // there are lots of other optional parameters ro wmMkProfilePOP3)
# wmMkProfilePOP3('myprofile', 'mail.myhost.com', 'username', 'pass');
#
# // (This code [below] is what will normally be found in the recipe)
# if (!wmInitPOP3('myprofile')) {
# ... (handle failure)
# } else {
# while (($msg = wmRetrievePOP3('myprofile')) !== false) {
# // $headhash is an associative array with, for instance,
# // $headhash['from']
# // $headers is an array of lines from the header section
# // $body is an array of lines from the body of the message
# list($headhash, $headers, $body) = $msg;
# # vvvvv OPTIONAL FROM HERE vvvvv
# # the following 3 lines support mime handling
# $bodytext = implode("\n", $body);
# $headtext = implode("\n", $headers);
# $mime = wmSimplifyMime($headtext."\n\n".$bodytext);
# # if I want just the 'text' portion of the message (not html, etc):
# $textmessage = wmTextMessage($mime);
# # if I want to mess with an attachment named "filename.txt"
# list($attach_type, $attach_content, $attach_name) =
# wmTextMessage($mime, "filename.txt");
# # if you wanted to write that attachment to disk...
# if ($fp = fopen($attach_name, "wb")) {
# if (!fwrite($fp, $attach_content))
# $msg = "Unable to write to \"$attach_name\".";
# fclose($uploadfp);
# }
# # ^^^^^ OPTIONAL TO HERE ^^^^^^
# ...
# }
# if ($WikiMailErr) { // often this section is unnecessary
# ... (wmRetrievePOP3 had errors - not just no more messages)
# }
# if (!wmClosePOP3('myprofile')) {
# ... (reference $WikiMailErr if desired)
# }
# }
#
# Normal usage for sending mail:
#
# wmSendMail($pagename, 'user@domain.com', 'subject',
# '(:include Group.Page:)');
# ---or (demonstrating sending to multiple addresses and using HTML format)---
# $recipients = array('user1@domain1.com', 'user2@domain2.com');
# $subject = 'some interesting subject';
# $message = "This is a much longer message which can optionally\n";
# $message.= "include markup such as (:include Group1.Page2:)";
# wmSendMail($pagename, $recipients, $subject, $message, '', '', '',
# 'html', true);
Utility Function Usage:
Release Notes
See AlsoContributors
Comments |