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 Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-04-06 -- SnipWire 0.8.6 (beta) released! Adds support for Snipcart subscriptions and also fixes some problems 2020-03-21 -- SnipWire 0.8.5 (beta) released! Improves SnipWires webhooks interface and provides some other fixes and additions 2020-03-03 -- SnipWire 0.8.4 (beta) released! Improves compatibility for Windows based Systems. 2020-03-01 -- SnipWire 0.8.3 (beta) released! The installation and uninstallation process has been heavily revised. 2020-02-08 -- SnipWire 0.8.2 (beta) released! Added a feature to change the cart and catalogue currency by GET, POST or SESSION param 2020-02-03 -- SnipWire 0.8.1 (beta) released! All custom classes moved into their own namespaces. 2020-02-01 -- SnipWire is now available via ProcessWire's module directory! 2020-01-30 -- SnipWire 0.8.0 (beta) first public release! (module just submitted to the PW modules directory) 2020-01-28 -- added Custom Order Fields feature (first SnipWire release version is near!) 2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Multi currency support Custom order and cart fields Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By bernhard
      #######################
      Please use the new RockFinder2
      #######################
      WHY?
      This module was built to fill the gap between simple $pages->find() operations and complex SQL queries.
      The problem with $pages->find() is that it loads all pages into memory and that can be a problem when querying multiple thousands of pages. Even $pages->findMany() loads all pages into memory and therefore is a lot slower than regular SQL.
      The problem with SQL on the other hand is, that the queries are quite complex to build. All fields are separate tables, some repeatable fields use multiple rows for their content that belong to only one single page, you always need to check for the page status (which is not necessary on regular find() operations and therefore nobody is used to that).
      In short: It is far too much work to efficiently and easily get an array of data based on PW pages and fields and I need that a lot for my RockGrid module to build all kinds of tabular data.

      Basic Usage

       
      Docs & Download
      https://modules.processwire.com/modules/rock-finder/
      https://github.com/BernhardBaumrock/RockFinder
       
      Changelog
      180817, v1.0.6, support for joining multiple finders 180810, v1.0.5, basic support for options fields 180528, v1.0.4, add custom select statement option 180516, change sql query method, bump version to 1.0.0 180515, multilang bugfix 180513, beta release <180513, preview/discussion took place here: https://processwire.com/talk/topic/18983-rocksqlfinder-highly-efficient-and-flexible-sql-finder-module/
    • By MoritzLost
      TrelloWire
      This is a module that allows you to automatically create Trello cards for ProcessWire pages and update them when the pages are updated. This allows you to setup connected workflows. Card properties and change handling behaviour can be customized through the extensive module configuration. Every action the module performs is hookable, so you can modify when and how cards are created as much as you need to. The module also contains an API-component that makes it easy to make requests to the Trello API and build your own connected ProcessWire-Trello workflows.
      Features
      All the things the module can do for you without any custom code: Create a new card on Trello whenever a page is added or published (you can select applicable templates). Configure the target board, target list, name and description for new cards. Add default labels and checklists to the card. Update the card whenever the page is updated (optional). When the status of the card changes (published / unpublished, hidden / unhidden, trashed / restored or deleted), move the card to a different list or archive or delete it (configurable). You can extend this through hooks in many ways: Modifiy when and how cards are created. Modify the card properties (Target board & list, title, description, et c.) before they are sent to Trello. Create your own workflows by utilizing an API helper class with many convenient utility methods to access the Trello API directly. Feedback & Future Plans
      Let me know what you think! In particular:
      If you find any bugs report them here or on Github, I'll try to fix them. This module was born out of a use-case for a client project where we manage new form submissions through Trello. I'm not sure how many use-cases there are for this module. If you do use it, tell me about it! The Trello API is pretty extensive, I'll try to add some more helper methods to the TrelloWireApi class (let me know if you need anything in particular). I'll think about how the module can support different workflows that include Twig – talk to me if you have a use-case! Next steps could be a dashboard to manage pages that are connected to a Trello card, or a new section in the settings tab to manage the Trello connection. But it depends on whether there is any interest in this 🙂 Links
      Repository on Github Complete module documentation (getting started, configuration & API documentation) [Module directory pending approval] Module configuration

    • By MoritzLost
      Process Cache Control
      This module provides a simple solution to clearing all your cache layers at once, and an extensible interface to perform various cache-related actions.
      The simple motivation behind this module was that I was tired of manually clearing caches in several places after deploying a change on a live site. The basic purpose of this module is a simple Clear all caches link in the Setup menu which clears out all caches, no matter where they hide. You can customize what exactly the module does through it's configuration menu:
      Expire or delete all cache entries in the database, or selectively clear caches by namespace ($cache API) Clear the the template render cache. Clear out specific folders inside your site's cache directory (/site/assets/cache) Clear the ProCache page render cache (if your site is using ProCache) Refresh version strings for static assets to bust client-side browser caches (this requires some setup, see the full documentation for details). This is the basic function of the module. However, you can also add different cache management action through the API and execute them through the module's interface. For this advanced usage, the module provides:
      An interface to see all available cache actions and execute them. A system log and logging output on the module page to see verify what the module is doing. A CacheControlTools class with utility functions to clear out different caches. An API to add cache actions, execute them programmatically and even modify the default action. Permission management, allowing you granular control over which user roles can execute which actions. The complete documentation can be found in the module's README.
      Plans for improvements
      If there is some interest in this, I plan to expand this to a more general cache management solution. I particular, I would like to add additional cache actions. Some ideas that came to mind:
      Warming up the template render cache for publicly accessible pages. Removing all active user sessions. Let me know if you have more suggestions!
      Links
      https://github.com/MoritzLost/ProcessCacheControl ProcessCacheControl in the Module directory CHANGELOG in the repository Screenshots


    • By Macrura
      PrevNextTabs Module
      Github: https://github.com/outflux3/PrevNextTabs
      Processwire helper modules for adding page navigation within the editor.
      Overview
      This is a very simple module that adds Previous and Next links inline with the tabs on the page editor. Hovering over the tab shows the title of the previous or next page (using the admin's built in jqueryUI tooltips.)
      Usage
      This module is typically used during development where you or your editors need to traverse through pages for the purpose of proofing, flagging and/or commenting. Rather than returning to the page tree or lister, they can navigate with these links.
      Warnings
      If you are using PW version 2.6.1 or later, the system will prevent you from leaving the page if you have unsaved edits.
      For earlier versions, to avoid accidentally losing changes made to a page that might occur if a user accidentally clicks on one of these, make sure to have the Form Save Reminder module installed.
      http://modules.processwire.com/modules/prev-next-tabs/
×
×
  • Create New...