Did you know ... Search Documentation:
Pack mail_merge -- prolog/mail_merge.pl
PublicShow source

This module provides a simple means to perform mail merge from a Prolog application: send personalized email message to a list of recipients. Here is a simple example:

mail_merge('Hello ~s how are you?',[['gianni@abc.com','Gianni'],
  ['stefi@cde.com','Stefi']],
  [subject('Hello'),from('Fabrizo'),auth(<google_user>-<google_password>)]).
 mail_merge(+Message:atom_or_string, +Addresses:list, +Options:list) is det
Perform mail merge using SMTP. Message is a format string as in format/2, Addresses is a list of lists, each sublist is of the form =[To|Fields]= where To is the recipient of the message and Fields contain the values to replace placeholders in Message. Message and Fields are passed to format/2 to produce the message. Options are passed to smtp_send_mail/3 from package smtp, they are:
  • smtp(+Host) the name or ip address for smtp host, eg. swi-prolog.org
  • from(+FromAddress) atomic identifies sender address. Provides the default for header(from(From)).
  • date(+Date) Set the date header. Default is to use the current time.
  • subject(+Subject) atomic: text for 'Subject:' email header
  • auth(User-Password) authentication credentials, as atoms or strings.
  • auth_method(+PlainOrLoginOrNone) type of authentication. Default is default, alternatives are plain and login
  • security(Security) one of: none, ssl, tls, starttls
  • content_type(+ContentType) sets Content-Type header
  • mailed_by(By) add X-Mailer: SWI-Prolog <version>, pack(smtp) to header iff By is true
  • header(Name(Val)) add HName: Val to headers. HName is Name if Name's first letter is a capital, and it is Name after capitalising its first letter otherwise. For instance header(from('My name, me@server.org')) adds header "From: My name, my@server.org" and header('FOO'(bar)) adds "FOO: bar"

Defaults are provided by settings associated to this module. host, port, security and auth_method are set by default to the values needed by gmail. If you use your gmail account you should just provide the option auth(<google_user>-<google_password>) You should also make sure that your google account has the option "Allow less secure apps" set to on. You can find the option in your account page under Apps with account access.