Jump to content
horst

WireMailSmtp

Recommended Posts

ok, this way it could be that some different mails has to be sent parallel, right?
 
You can go this way: (simplified)
 
    - sentLogReset isn't needed in your case, because you collect all recipients in the field $message->recipients.
   
    - you need to hook into sentLogGet, here you read all recipients from $message->recipients.
 
    - for each successfull sent message you should drop the recipient from the $message->recipients field in the hooked method sentLogAdd
      (don't forget to save the page)
      here you also can add a message to a textarea field
 
      Edit: striked the above, - see this post, it has a more correct solution
 
This way it should be possible to add some hundred recipients to the initial collection and if a script execution got interrupted, it could be resumed with the next cron run.
 
The only thing that you have to take care for is to determine if a page is allready sending. (no simultaneous sending of the same page!)
 
Hhm, maybe also it should not send different pages simultaneous?! Only one page after each other?
 
 
The used php libs allready provide personalized emailmessages in a faster way than to create and encode a new mail for each recipient. So, to use it in its meant fashion, it is needed to extend the current module. If you like and if it is possible that you can send me (only) the basic template code for the emailpages we can achieve that together.
 
 
Edit:
Oh, hasn't read your gists before.
 
Some questions:
- Is it possible to setup the cron to only start a new instance if the previous started one (5 minutes before) has allready finished? (but skip it if the previous one is still running)
 
- What would be the max number of recipients you can think of you will be collect for a mail (in the next 2 years) using this approach?

Edited by horst

Share this post


Link to post
Share on other sites

Hi Horst -

regarding the cron - since the cron just executes the page with this template (only way i could do it for the moment), i guess the thing would be to have some logic at the top of the template file to check is wiremail is still running? would that be possible? i definitely see your concern as far as scalability and different use cases; In my case i know for sure that i wouldn't have 2 messages scheduled 5 min apart with enough recipients to consume more that 5 min of sending time; but it is definitely something that should be accounted for...

When i first started this i was initially only thinking of sending to maybe 1-5 recipients at a time; now i figure that i could possibly need to send out to as many as 150; I was sort of figuring that when/if i get to the point of needing to send to a larger # that i would use a different system;

Another thing that i might play with is the Mandrill web hooks - it lets you enable posting back to a URL the json response for different events, like mail sent, mail opened, bounced etc; could be cool to have some fields in processwire to show the results of the send without having to go and look at the mandrill interface each time... I'll let you know how this goes.. should have some progress on it in a few days; the other good thing about reading back the mandrill responses is that they don't store that data for very long, so would be good to keep those records in PW...

Share this post


Link to post
Share on other sites

@Macrura: I think with a peak of 150 recipients you can go like in your second gist with the replacements (regarding personalization) and send them one after the other. But you need to use sendBulk(true) !!

Has you tried to use gmdate? Did it solve the issue?

// LOGGING:

you need to add a field to the messages template / pages that can collect the successful used recipients emailadresses!

(I use a textfield or simple textareafield named $message->recipientsSuccess in the following example)

// at the top of the template add the hooks

    // the sentLogReset isn't needed to hook into.
    // If you want to reset it, just delete the value of the $message->recipientsSuccess field!

    // this hook read in all successful used recipients
    wire()->addHook("wireMail::sentLogGet", function(HookEvent $event) {    
        $p = wire('page')->tmpMessagePage;  // get the current processed message-page
        // read the emailadresses from the recipientsSuccess field
        $emailaddresses = unserialize(trim($p->recipientsSuccess));  // you may also use json instead of serialized code or any other solution
        if(!is_array($emailaddresses)) $emailaddresses = array();    // should return an array !!  
        $event->replace = true;
        $event->return = $emailaddresses;
        return $emailaddresses;
    });

    // this hook add recipients to the successful collection and log the success
    wire()->addHook("wireMail::sentLogAdd", function(HookEvent $event) {    
        $p = wire('page')->tmpMessagePage;  // get the current processed message-page
        $emailaddress = $event->arguments[0];
        $logentry = "From: {$p->tmpFrom}; To: {$emailaddress}; Subject: {$p->tmpSubject}\n";
        // here you need to add the recipient to the successfull recipients collection
        $tmp = unserialize(trim($p->recipientsSuccess));  // you may also use json instead of serialized code or any other solution
        if(!is_array($tmp)) $tmp = array();               // should return an array !!
        $newRecipientsCollection = array_merge($tmp, array("{$emailaddress}"=>"{$emailaddress}"));
        $p->of(false);
        $p->recipientsSuccess = serialize($newRecipientsCollection);
        $p->email_log = $p->email_log . $logentry;
        $p->save();
        $event->replace = true;
        $event->return = true;
    });

When starting the wiremail instance, you need to setup it to use the sentLog functionality:

$mail = wireMail()->useSentLog(true)->sendBulk(true);  // don't forgett this !!!

At the end of your $messages loop you need something like this:

// Send

    // add some temporary vars to the current page, so it simply can be read within the hooked functions
    $page->of(false);
    $page->tmpFrom = $message->identity_select->email;
    $page->tmpSubject = $title;
    $page->tmpMessagePage = $message;
    $page->save();
    $page->of(true);

    // send the mails
    $numSent = $mail->useSentLog(true)->sendBulk(true)->send();  // useSentLog: you also can set it here !

    // ready with this $message page 

I haven't tested it but something like this should work & you get the idea I think. :)

Share this post


Link to post
Share on other sites

@Horst - a zillion thanks for this, looks awesome - i will delve in to deep study on this tonight (NY time) and respond then... gotta go and work for $ now...!

Share this post


Link to post
Share on other sites

Hey, Can anyone help with me this?

I'm trying to send mail with this module, however I keep getting this in error log "No unauthenticated relaying permitted".

How can I resolve this?

Note:

I'm using ipage shared hosting environment. Ipage told me i don't need to log in to their mail server to send mail. So i'm not sure what I am doing wrong.

Code I'm using is this...

$mail = wireMail(); // calling an empty wireMail() returns a wireMail object
 
$numSent = wireMail($to, '', $subject, $textBody); // or with a default sender emailaddress on config page 
  • Like 1

Share this post


Link to post
Share on other sites

@JasonS: this module lets you connect and send messages through an SMTP server.

Do you have filled in the needed credentials in the config screen of this module?

Does the connection test succeed or fail?

Share this post


Link to post
Share on other sites

@horst : No, IPage said it didn't need any credentials.

Connection test is always successful.

  • Like 1

Share this post


Link to post
Share on other sites

The connection-test uses your credentials and try to establish a connection to the server you has entered in the configscreen together with your credentials.

If the connection-test always succeed, there is no reason why the connection when trying to send a mail shouldn't do so too. (Because it is 100% the same code used in both cases, and the same credentials, empty or not.)

The error you are getting tells another story: "No unauthenticated relaying permitted"

- Do you have a personal SMTP account at ipage?

- Have you asked them if you need credentials for sending through your personal SMTP-Account and they have answered to you that you do not need those?

- Or do you have asked them if you need credentials for sending emails via php, and they think you mean simply using the php mail() function through your webhost?

The wiremailSmtp module cannot use php's native mail() function. This can be used with the base class wiremail and without credentials.

  • Like 2

Share this post


Link to post
Share on other sites

I contacted iPage again, and indeed you were right, I did need the credentials for the SMTP-account to work.

Before they told me I didn't, maybe as you said, they may have been thinking i was using the mail() function.

Once I added the credentials for my account, it worked beautifully.

Thank you very much Horst!!! :)

  • Like 1

Share this post


Link to post
Share on other sites
If the connection-test always succeed, there is no reason why the connection when trying to send a mail shouldn't do so too. (Because it is 100% the same code used in both cases, and the same credentials, empty or not.)

I had a similar situation the other day with a gmail smtp setup. The test connection worked fine, but the email didn't send. Turns out the test worked with a few different config setups, but the email only sent with one specific setup. So I think a successful test connection is not always a guarantee that everything is set up correctly. Not sure that your module can do anything about that though.

Share this post


Link to post
Share on other sites

I had a similar situation the other day with a gmail smtp setup. The test connection worked fine, but the email didn't send. Turns out the test worked with a few different config setups, but the email only sent with one specific setup. So I think a successful test connection is not always a guarantee that everything is set up correctly. Not sure that your module can do anything about that though.

Ok Adrian that may be right, but I think you have entered your credentials for the SMTP account(?). In this special case JasonS hasn't entered any credentials and got everytime a "No unauthenticated relaying permitted" in the error-log. Also he said that the test-connection works everytime! Hhm? Finally he has found that he need credentials for using the SMTP server, (not a big surprise at all, :lol: isn't it?). The times when you could use a mail relay without authentication are gone for a decade or two! :) We have 2014.

Share this post


Link to post
Share on other sites

Hey horst - I am not really up on the latest with this, but just to give you an idea, I can get a successful test with gmail with only:

smtp.gmail.com 

587

use START_TLS

with no credentials entered at all. Not sure if this is unique to gmail. I agree though, I thought most SMTP servers required authentication these days. It seems that gmail doesn't actually send a message, but the test is still successful without.

BTW, the settings that actually do send an email via gmail for me are:

smtp.gmail.com

465

use SSL

email and password as credentials

NB: I actually need to turn off use START_TLS

  • Like 1

Share this post


Link to post
Share on other sites

Sure?

This would make the testconnection nearly useless. The only reason for it is to test if one has no typos in the server settings and credentials.

I will try this gmail and with other servers and report back.

Share this post


Link to post
Share on other sites

Wow! I have found out that in the Connect() method of the base SMTP class it comes to a point after trying to start a TLS connection that a variable $success is set to true if the smtp-server simply supports TLS.

After that a if condition checks if there are settings available for user, if not it passes through to the end of the method with $success set to true! A Bummer!

If there is given a username, it trys to authenticate that user and the variable $success is set to that result.

So, at least this is not a bug, because in the past or in private networks SMTP servers could be configured to work without authentication, that is what this class does.

What should I do with this situation? I tend to ignore a usage without user authentication. This way it tries everytime to establish a connection via authentication, what will fail with an empty user or pass.

Good to know that typos would be detected in the past but only empty usernames raised this behave.

Now the class gives two errors:

WireMailSmtpConfig: ERROR: SMTP settings did not work.
WireMailSmtpConfig: 535 5.7.8 Error: authentication failed
Edited by horst
  • Like 3

Share this post


Link to post
Share on other sites

I have updated the Github repo and the entry in the modules directory to version 0.1.9

@JasonS: sorry that I tend not to believe that a server says success on testconnection and then returns a "No unauthenticated relaying permitted" error. Together with the confusion that the hoster has said it needs no credentials, it sounded too unlikely for me. But it was real. I have liked all posts of you here in the thread trying to say appologize. (If you post one more I will like it too) :-[

  • Like 1

Share this post


Link to post
Share on other sites

@horst lol, It's ok :) I understand. I was confused as well for a long time about the test connection but i'm glad we were able to get it resolved.

  • Like 1

Share this post


Link to post
Share on other sites
I posted 2 times in another topic about the SMTP settings for Google.  Here is the consolidated information from those posts:

If you use a Google email address, this will work:

 
post-756-0-39162500-1413431424_thumb.png
post-756-0-38911900-1413431441_thumb.png
 

Other major providers are setup similar (you just need to check what their SMTP requirements are - this information is easily found, otherwise ask your hosting provider for correct setup and ports)

-------------  Second Post -----------------

I will & here is additional information regarding Gmail.  There are specific variations that will work and sometimes people don't understand why an option is needed.  These links should educate anyone on why certain settings work and others don't.

  • Like 8

Share this post


Link to post
Share on other sites

I don't know why but when I use my work email address which is managed by Gmail, but is not a @gmail address, I need to use:

post-985-0-83709400-1413492743_thumb.png

Nothing else seems to work for me except this.

Hopefully that might be a useful addition to @cstevensjr's excellent post.

  • Like 4

Share this post


Link to post
Share on other sites

Adrian, that's a valid sequence when using SSL (Port 465 is required).  Port 587 requires TLS.  The first link I posted explains what normally works, according to Gmail themselves.  I host with Dreamhost and when I was using ActiveCollab, I could use either or both within that application.  Gmail has other relay addresses that also work.

Here's Dreamhost's take on SMTP/SSL/TLS

http://wiki.dreamhost.com/Secure_E-mail

I'm no Gmail or SMTP expert, so I usually just play around with the settings until I get one that reliably works.

I don't think there is a default right answer to getting your mail to send reliably, because we are dealing with different email vendors, Operating Systems, Webhosts and other factors we don't even know about.

  • Like 6

Share this post


Link to post
Share on other sites

Hi Horst: When testing the connection and 'use SSL' is checked these 2 notices appear. (2.5.17 dev)

Notice: Undefined property: smtp_class::$result_code in /Users/martijn/Sites/domains/newsletters/htdocs/site/modules/WireMailSmtp/smtp_classes/smtp.php on line 1032

Notice: Undefined offset: 0 in /Users/martijn/Sites/domains/newsletters/htdocs/site/modules/WireMailSmtp/smtp_classes/smtp.php on line 1042
  • Like 1

Share this post


Link to post
Share on other sites

@Martijn: I cannot replicate this. I have no errors in the logs and I have no error outputs. Error display is set to strict all. I'm on PW 2.5.11

Which version of WiremailSMTP do you use?

Do you have set a smtp- hostname, user and pass? Or do you have left one / some fields empty?

Share this post


Link to post
Share on other sites

Few Qs:

1. How to change authentication (SMTP host, user/pass/etc) from API?

2. How to set "Reply-To" (different from "from" one) from API?

Share this post


Link to post
Share on other sites

Regarding No. 1:

$data = $modules->getModuleConfigData('WireMailSmtp');
$data[$key] = $value;
$modules->saveModuleConfigData('WireMailSmtp', $data);  

Fill in key and value yourself. It's the same for any other modules settings.

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By robert
      I often had the need for an overview of all used fields and their contents for a specific page/template while developing new websites without switching to the backend, so I made a small module which lists all the needed information in a readable manner (at least for me):
      Debug Page Fields
      https://github.com/robertweiss/ProcessDebugPageFields
      It adds two new properties to all pages:
      $page->debugFieldValues – returns an object with all (sub-)fields, their labels, fieldtypes and values $page->debugFieldTypes – returns an object with all fieldtypes and their corresponding fields // List all values of a pages $page->debugFieldValues // List a specific field $page->debugFieldValues->fieldname // List all used fieldtypes of a page $page->debugFieldTypes I recommend using it in combination with Tracy Debugger, Ray, Xdebug etc. as it returns an object and is only meant for developing/debugging uses. 
      For now, the fieldtype support includes mostly fieldtypes I use in my projects, but can easily be extended by adding a new FieldtypeFIELDNAME method to the module. I use it with five different client installations (all PW 3.0.*), but of course there might be some (or more) field configurations which are not covered correctly yet.
      Supported fieldtypes
      Button Checkbox Color Combo Datetime Email FieldsetPage * File FontIconPicker Functional Image ImageReference MapMarker Multiplier Mystique Options Page PageIDs PageTitle Radio Repeater * RepeaterMatrix * RockAwesome SeoMaestro Table Text Textarea Textareas Toggle URL * The fields with complete subfield-support also list their corresponding subfields.
      Installation
      Download the zip file at Github or clone the repo into your site/modules directory. If you downloaded the zip file, extract it in your sites/modules directory. In your admin, go to Modules > Refresh, then Modules > New, then click on the Install button for this module. As this is my first ›public‹ module, I hope I did not miss any important things to mention here.
    • By Cybermano
      Food Allergens Module
      A simple List of Food Allergens
      My needs were to provide a simple list of food allergens for our clients with restaurant related activity.
      The idea was to simply output the list (to speed up the data entry) without leaving the food menu editing, eg. opening another page in new tab or window.
      This isn't a perfect solution, but it works fine for my needs and I decided to share the base idea.
      This could also be easily used to show little notes or short "vademecum", not only for the list of food allergens.
      ---
      Main features
      The basis
      All moves from a short editing of the module in this tutorial: How to create custom admin pages by @bernhard
      First of all it creates an empty admin page, with a dedicated permission to let safe-user to see it (this permission has to be created as a new ones, manually or by the module).
      Once the page is created, I have hooked its behaviour into the ready.php, to show the content (basically a list).
      A step further
      With the tips of  @bernhard, @Soma (and many others), see here , the magic happens. 
      The new page will be shown as a panel, so editors will not abandon their data entry to have a quick view to the list.
      A little further
      Why scroll to the top of the page to click a link?
      The next step was to create a sticky button only in the food menu pages.
      Again with a @bernhard tip I moved into the customization of this simple module and the related hook.
      ---
      How to use this module
      After installed, it creates the page /admin/page/allergens/ and the module is to be setted up. The first field is a CKEditor with multi-language. This is the place where to write the informations that will be shown into the page. The next field is a simply text-area where to place a bit of JS that will be appended to the markup of the text (omit the 'script' tags). I also putted a checkbox with a silly statement: this to think at least twice on the safety of the written JS. Now comes the first way to display the link to the page
      Field Note with Link. Enable and save it. The module will display a new row with 4 selects (1 standard and 3 ASM):
      View mode (to show the page as Panel or as Modal PopUp); Templates to select: select one or more and save before proceed, so the  asm-select of the pages will be populated showing all the pages of the selected templates. Pages to select: also here select at least one and save before proceed to populate the asm-select for fields only with the ones that belong to the selected pages. Select the fields where to place the note and save again. That's all: now you will find into the notes of the selected fields the link "See the List of Allergens".
      At the same way, the option for the sticky button, but with a plus
      The field select is obviously unnecessary, but you could play with the last row: the inline styles to fix your sticky button where you like. Here you could set the sticky position of the <div> and the absolute ones of the <a>.

      Video Explanation
      In these screencasts you could see a custom JS that show a "copy" button near a "hanna-code" call.
      This because I've set a specific one for each allergen to show up a tooltip in the front end.

      Registrazione #33.mp4  

      Registrazione #34.mp4 ---
      Last but not the least
      Actually it works fine for my needs, even if it's much improvable: I'm working on the permissions creation, the uninstall section, a separate configs and defaults and how to include the hook into the module leaving free the ready.php. According to a simpler uninstall. Also I would make the link text as a dynamic text field, so it will be more flexible.
      I always learn a lot here, so I would share my code for whom it could be interested.
      I removed the hanna code references, but I provide you the html list of the allergens, English and Italian too, so you can paste them into the "source" of the CKEditor field to have a ready to use module.
      Obviously you are free to modify the code as per your needs.
      Please, keep in mind that I'm not a pro coder and I beg your pardon for my verbosity (speaking and coding). 😉
      I hope be helpful or for inspiration.
      Bye
      ready.phpList-ITA.htmlList-ENG.htmlAllergens.module
      README.md
    • By Robin S
      This module is sort of an upgrade to my earlier ImageToMarkdown module, and might be useful to anyone working with Markdown in ProcessWire.
      Copy Markdown
      Adds icons to images and files that allow you to copy a Markdown string to the clipboard. When you click the icon a message at the top left of the screen notifies you that the copying has occurred.
      Screencast

      Note: in the screencast an EasyMDE inputfield is used to preview the Markdown. It's not required to use EasyMDE - an ordinary textarea field could be used.
      Usage: Images
      When you hover on an item in an Images field an asterisk icon appears on the thumbnail. Click the icon to copy an image Markdown string to clipboard. If the "Description" field is populated it is used as the alt text.
      You can also open the "Variations" modal for an image and click the asterisk icon to copy an image Markdown string for an individual variation.
      Usage: Files
      When you hover on an item in a Files field an asterisk icon appears next to the filename. Click the icon to copy a link Markdown string to the clipboard. If the "Description" field is populated it is used as the link text, otherwise the filename is used.
       
      https://github.com/Toutouwai/CopyMarkdown
      https://processwire.com/modules/copy-markdown/
    • By BitPoet
      I've realized that I've been jumping back and forth between the PW API docs and the source code for site modules far too much. The idea to hold all necessary documentation locally in one place has occurred to me before, but getting PHPDocumentor et al set up and running reliably (and producing readable output) as always been too much of a hassle. Today I was asked how I find the right hooks and their arguments, and that inspired me to finally get my backside down on the chair and whip something up, namely the
      Module Api Doc Viewer
      ProcessModuleApiDoc
      It lets you browse the inline documentation and public (optionally also protected) class/method/property information for all modules, core classes and template files in the ProcessWire instance. The documentation is generated on the fly, so you don't have to remember to update your docs whenever you update a module.
      The module is quite fresh, so expect some bugs there. Behind the scenes it uses PHP-Parser together with a custom class that extracts the information I needed, and the core TextformatterMarkdownExtra module for rendering the description part in the phpdoc style comments.
      This is not a replacement / competitor to the API Viewer included in the commercial ProDevTools package. There is quite some information included in the inline documentation that my module can't (and won't) parse, but which makes up parts of the official ProcessWire API docs.
      This, instead, is a kind of Swiss army knife to view PHPDoc style information and get a quick class or function reference.
      If you feel daring and want to give it a spin, or if you just want to read a bit more, visit the module's GitHub repository.
      This is the overview page under "Setup" -> "Module API Docs":

      And this is what the documentation for an individual class looks like:

      The core module documentation can of course be found online, but it didn't make sense not to include them.
      Let me know what you think!

    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.
      https://github.com/techcnet/ProcessFileManager

      Warning
      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      Dragscroll
      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
       
×
×
  • Create New...