Jump to content

New module type: WireMail


ryan

Recommended Posts

Nope - can't see it in the latest dev.

I'm going to put a note about it on GitHub and then if it gets included you can specify PW 2.5 as a minimum requirement.

  • Like 2
Link to comment
Share on other sites

Is bcc already implemented? Going to recode my Newsletter module and would need this functionality.

Nope - can't see it in the latest dev.

I'm going to put a note about it on GitHub and then if it gets included you can specify PW 2.5 as a minimum requirement.

Until then you may use the WireMailSmtp class. It has to, cc and bcc functions and I think Ryan will use the same names for the functions.

  • Like 1
Link to comment
Share on other sites

I'm going to require WireMailsMTP anyway and will explain how to add mandrill SMTP to it. So my newsletter module will finally have a solid sending base. Better then php mail() and getting blocked as a spammer. 

@horst:I still have our conversation about this in my head :) 


I even saw the "bulk" mail option in your module which is great for this :)

  • Like 4
Link to comment
Share on other sites

  • 1 month later...

I'm working on a WireMailSendgrid module to send mail out through sendgrid.com. The module has settings for the Sendgrid credentials and a path pointing to some handy PHP code provided by Sendgrid (their "sendgrid-php" library for working with the API). I still have some features to build out but it works when I use it like this:

$mail = new WireMailSendgrid();
$result = $mail->to('steve@foo.com')->from('test@foo.com')->subject('WireMailSendgrid test message')->body('Message Body')->send();
 

Okay, those aren't the real email address but with real ones it works just fine.

Q: I've read in the first post: "give it no arguments, and it'll return whatever WireMail module is installed." How does that happen? Aside from installing my WireMailSendgrid module is there another step? I don't see how core's WireMail would know to use it.

If I do the above test using $mail = new WireMail(); instead of $mail = new WireMailSendgrid(); it doesn't use my module. I have statements in the construct method which write to a text log so it's easy to tell.

By the way I'm doing the tests on a fairly empty Processwire site which was 1.4 and then upgraded (with ProcessWireUpgrade) to ProcessWire 2.4.18 dev. PHP is 5.4.23.

Thanks in advance.

Link to comment
Share on other sites

@SteveB: you may compare how it is built / used with WireMailSwiftMailer or WireMailSmtp.

Both are modules that set on top of the base class and just working fine. So, without knowing how you have coded it, I cannot tell you more than to compare yours to those and refer to their examples.

--------

It also is possible to check for the right module like so (logging isn't necessary):

$mail = wireMail(); 

if($mail->className != 'WireMailSendgrid') {
    // Uups, wrong WireMail-Class: do something to inform the user and quit
    echo "<p>Couldn't get the right WireMail-Module (WireMailSendgrid). found: {$mail->className}</p>";
    return;
}

As a sidenote, you should only install one module on top of the base class. I have encountered that, if you install two, the last one installed is used. I don't know of any method to select from different modules through the WireMail base class.

Link to comment
Share on other sites

Thanks Horst. I found 2 small but important goofs and it's all fixed now. :)

I need to test a bit more and decide about features that are not in the base class. As has been pointed out already that could get messy as these modules proliferate. As far as Cc and Bcc, this one is like WireMail in that it passes the list of email addreses to SendGrid which sends each recipient a separate email so the recipient won't see anyone else's email address.

  • Like 1
Link to comment
Share on other sites

  • 8 months later...

If I wish to make two wireMail calls one after the other - how do I reset the member vars set in the first call?

$mailOne = wireMail();
$mailOne
   ->to('recip@one.com', 'recip one')
   ->from('some@address.com', 'Sender One')
   ->subject('Subject one')
   ->bodyHTML($htmlMsg)
   ->send();

$mailTwo = wireMail();
$mailTwo
   ->to('recip@two.com', 'recip two')
   ->from('some@address.com', 'Sender Two')
   ->subject('Subject two')
   ->send();

$mailTwo appears to have both recipients recip@one.com and recip@two.com, and also has $bodyHtml content set from the first wireMail instance. I'd like all $mailTwo member vars to be unset to being with. I would have thought this was default behaviour, where am I going wrong? Are $mailOne and $mailTwo not complete separate instances of wireMail?

Link to comment
Share on other sites

Yeah thx @tpr, that's what I was originally doing. However I was extending wireMail with added the module WireMailMandrill to send via Mandrills API, but this in conjunction with new wireMail(), causes the WireMailMandrill function tags() to throw an error: tags does not exist or is not callable in this context

$mailTwo = wireMail();
$mailTwo
   ->to('recip@two.com', 'recip two')
   ->from('some@address.com', 'Sender Two')
   ->subject('Subject two')
   ->tags('my tag')
   ->send();
Link to comment
Share on other sites

Thanks for bringing this up! I'll have a look at this shortly :)

If you have changed it to singular: false in your own copy, does that change alone fix the problem you had?

Link to comment
Share on other sites

  • 7 months later...

I feel maybe I could help to clarify some things, as long as I got them right myself :P  (and maybe I can learn something..)

There are two things available

The function wireMail() from /wire/core/Functions.php (lowercase w)

and the class WireMail() from /wire/core/WireMail.php (uppercase W)

As far as I understand the code only the function will automatically check if there is a module installed extending WireMail class

So if you don't want to use the function (for whatever reason) but want to use the extended class you have to call it directly like new WireMailSmtp()

(for this I think the module has to be of type autoload (right?)

Is it possible to call a function with new? like new function()?
Aha, if it returns a class than it should work..?!

And the class is what you extend or what gets extended..

Maybe I'm wrong and everyone in this thread is on the right track already. If so it maybe helps following people   ;) At least I needed some minutes to figure this out..

Saludos, Can

Link to comment
Share on other sites

  • 2 months later...

However the mail send from as www-data@mydomain.com

Looks like the server overwrite your setting after wiremail sends it. You need to refer to your server settings and change them.

  • Like 1
Link to comment
Share on other sites

Is there a way to add the 'reply to' address using the core WireMail please? All else with the module is working fine but I couldn't see this function.

I did note the extra_parameters function but can't find out anywhere if there is a command under extra parameters to set 'reply to'?

Thanks in advance!

Geoff.

Link to comment
Share on other sites

Is there a way to add the 'reply to' address using the core WireMail please? All else with the module is working fine but I couldn't see this function.

I did note the extra_parameters function but can't find out anywhere if there is a command under extra parameters to set 'reply to'?

As the normal WireMail uses php's mail() to send mails you can see all possible settings at http://php.net/manual/en/function.mail.php

So you in PW it should be

$mail->header('Reply-To', 'webmaster@example.com');

Haven't tested it but should do what you want ;-)

  • Like 4
Link to comment
Share on other sites

I have a problem with modules using WireMail. It is probably due to my PHP/Postfix settings after transferring to a new server. Also: I am using PW 3. I was using PW 2 on the old server. Both old and new ran PHP 7.

For example, with the Email New User module, the code for sending a test message doesn't work:

wireMail(wire('user')->email, $data['fromEmail'], $data['subject'], self::parseBody($data['body'], $data['fromEmail'], wire('user'),
'password'));

While replacing it with the following works:

$mail = wireMail();
$mail->to('somemail@somesite.com')->from('myemail@site.com');
$mail->subject('Mail Subject');
$mail->body('Mail Body');
$mail->bodyHTML('<html><body><h1>Mail Body</h1></body></html>');
$mail->send();

I can use whatever address in the "from" email - it delivers even if it is not from the same domain.

According to adrian's suggestions, I added bd() dump functions to feed the contents of the data going to wireMail to Tracy debugger and everything had the correct content.

Another example: this template code that alerts superusers about new registrations (uses the FrontendUser module) no longer sends emails:

 $form->addHookAfter('FrontendUser::save', function() use($fu, $input) {
    $superusers = wire('users')->find("roles=superuser");
    $emails = $superusers->explode('email');
    $subject = "Registration: " . $fu->userObj->fullname;
    $emailContentPlain = "content";
    $mail = wireMail();
    $mail->to($emails);
    $mail->from('admin@mysite.com');
    $mail->subject($subject);
    $mail->body($emailContentPlain);
    $mail->send();
  });

It is weird as the format for calling wireMail is exactly the same as in the code that works for me. I think it can't be about any PW 3 incompatibility, as wire() is used everywhere and just works.

How can I troubleshoot this?

Link to comment
Share on other sites

I'd die and dump stuff in the WireMail class to see if right before things are actually sent using mail() if all necessary data are really there.

How can I do this? Do you mean I have to edit wire/core/WireMail.php and make it die and log to a file?

Link to comment
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.
×
×
  • Create New...