Custom mail spool in symfony 1.4 - email

Can anyone give me a rough idea or link to instructions on how to create custom symfony swift mailer spool? I currently have the basic Doctrine spool which sends messages and deletes queue item.
I would like to do following:
Have a field with status (Sent, Unsent, Failed, Email does not exist, etc)
Update status field instead of deleting queue item on send

I've never done such functionality myself, but it seems like you can create your own spool class:
<?php
class Swift_MySpool extends Swift_DoctrineSpool {}
Have a field with status (Sent, Unsent, Failed, Email does not exist, etc)
The Swift_DoctrineSpool class supports an option called model, where you can pass a name of class to store your mail at. So, just creating your custom model will take effect.
Update status field instead of deleting queue item on send
Override queueMessage() and flushQueue() methods in your class and refer to Swift_DoctrineSpool at symfony API.
Hope this will help.

Related

Play - Custom validations with custom error message

I am using the Play framework in Scala to develop a small blog website. I currently have a form (successfully) set up for an easy registration of users. This login page just accepts a username (ie. no password yet), verifies that is of the appropriate length and doesn't exist yet, and adds this user to the database (currently still in memory). Length can be verified using just the basic form functionality, however, the uniqueness of this username required me to use custom validations.
Now, this all works, except for the custom error message. When a normal form requirement is not fulfilled, an error message is returned and displayed in the view (eg. "The minimum length is: 5"). I want to display a similar message when the name is not unique. In the first link I provided there is an example of custom validations which seems to have an argument that represents such custom error message for validations you write of your own. However, this does not display in the view, while the others do.
Current validation code:
private val myForm: Form[Account] =
Form(mapping("name" -> text(3, 24))(Account.apply)(Account.unapply).verifying(
"Account is not in the DB.",
fields =>
fields match {
case data: Account => accountExists(data.name).isDefined
}
)
)
Anyone has any ideas?

Salesforce send Email by Apex

I'm making by a requirement a code able to send an E-mail to an specific list of E-mails, due the fact that I must to include the attachments of the record I decided to use an apex class instead an e-mail alert. This object (A custom object ) must populate some fields in an email template with some of the record´s fields. I implemented the following code
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(lista);
mail.setTemplateId('00X21000000QR22');
//mail.setWhatId(idMinuta);
mail.setTargetObjectId('005d0000005NMIx');
mail.setSaveAsActivity(false);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for (ContentVersion document: documents)
{
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(document.Title);
efa.setBody(document.VersionData);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
I understood that to make the fields merge it´s necesary to use the WhatId method. In the related code, I have commented it because It generates an error (INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.)
My question is, if is it possible to do this with a custom object. I´m a little confuse with salesforce documentation beacuse it looks like the method supports a custom object, or maybe If I am forggeting something to include in the code.
If i keep the WhatID line commented, effectively the email is sent with the attachments and the Template but it is not populated.
I really need this kind of solution because the org have in this object at least 20 email templates, for me will be easier just to pass the Id of the template instead of makig a code with 20 different html codes for each situation
Thanks a lot
Please publish this question at Salesforce StackExcahnge https://salesforce.stackexchange.com/

Logging with Email and Password , Not with Username Yii 2

How I can manage to login with email address,not with the standart (username + password).I enter the website with my Users in my DataBase , but is there a way to change that to be with email address instead of that user name , because when I use Gii , I got a lot of errors , even I try to fix those errors
First, try to locate your SiteController or any other Controller you use for the index route. It should have an action function that corresponds to the login route; it is usually with signature public function actionLogin().
You should see the initialized model (usually, the LoginForm model). The model should have a function for login logic which is checked to determine user authenticity. You should find that this function invokes another login function which requires the User object as first argument/parameter. The function is usually the $this->getUser() function.
Looking into this will point to you a call to the actual data model that fetches user by whatever criteria/property you specify; this can be email or anything else that might not even need be unique but generally, you want to use a unique data property like username and email. This function relies on the User data model. It, by Gii default, calls the function User::findByUsername(search_property)
Yii2 provides a default User model that implements the Identity interface; that's where you want to make the adjustment you need. It should have the required static function findByUsername() or something similar. You would find that Yii2 default searches within static data to find user, you should link that to you (User) data model which I assume you generated using Gii.
My Gii sequence usually looks like such:
List item
Generate the yii2-basic/yii2-advanced using composer
Create Database (I have a user table in there) and set proper db credentials in config/db.php
Rename the default model/User.php to model/OldUser.php
Create Data Models using Gii
Make the newly generated User Model implement IdentityInterface to allow Yii2 freely-given session management by adding implements yii\web\IdentityInterface to the class declaration.
Implement all the required methods of the IdentityInterface. You can check in `model/OldUser.php' for guidance.
Create static functions to findUserByEmail($email) or findUserByUsername($username)
Mine usually look like this
I hope this helps.
I made it just change everywhere where must be email,instead of username,because of Yii default username loggin , thank u for the advices

Zend Mail - Where to instantiate it?

I'm using a Data Mapper / Gateway design pattern.
So I have a:
Mapper;
Gateway;
Domain Object (mainly with getters and setters);
A controller;
A view.
My question is: where should I instantiate the Zend Mail ?
I believe the view is obviously out of question, and the gateway is, as well, not to be considered.
The controller should be kept clean, so:
Mapper our Domain Object ?
If our form will have some select box that will retrieve data from the database, then, perhaps the Mapper will be the most appropriate place to instantiate Zend Mail ?
Thanks
Hmmmm? Well with Zend you can configure your Zend_Mail in your bootstrap or by using the application.ini file or some other config file. That's how I configure mine right now. For dev, I'll write the mails to a file and for testing I'll do mail over an actual mail server.
I instantiate my Zend_Mail instance in a class that I call Mail_Service. This mail service class will create a Zend_Mail instance internally when it needs to send a mail and will use an existing Zend_Mail instance if one has been created and more mails need to be sent.
It has methods that will send predefined mails for me. For example,
Mail_Service->sendWelcomeEmail( $userInfo )
OR
Mail_Service->sendActivationEmail( $userInfo )
Say for example my controller gets a request to create a new user, then the over all flow of my code will be like this
//in the controller
//process form from browser somehow
UserAccountService->createNewUser( $userInfo );
/////////////////
/// Within the user account service
public function createNewUser( $userInfo )
{
$userMapper->createNewUser( $userInfo );
$preferencesMapper->createDefaultPreferencesForUser( $userInfo );
MailService->sendWelcomeEmail( $userInfo );
}
I don't know if this is the best way to do it, but this way my service have function
names that are relevant to the service and capture a whole work flow instead of being atomic operations that just forward calls to other objects.
Hope this helps.
I always keep code that sends mail in my controllers.
Model - database/business logic
View - html / presentation layer
Controller - The code that does stuff.

Drupal: How to automatically send (cck) node content + file attachment via email

I am still quite new to Drupal and have very limited programming skills.
I am trying to build a job board site using cck + views. I have created 2 related content types: a "job post" and a "job application" - both are related using a nodereference field.
The job application node has 4 fields: id of the job post to which the person is applying, email of the applicant, cover letter (body field) and attached cv (cck field that allows users to attach/upload a document).
Question: Once a job application is created I would like the content of the node (including the attached file) to be automatically sent via email to the person who posted the job (destination email address is in a cck field in the related "job post" node).
Thus my requirements are: (1) to automtically "transfer" the destination email address from the "job post" content type to the "job application" content type; and (2) to automatically send all the "job application" node contents + file attachment to the destination email.
Is there any module that can help me achieve this?
Thank you so much for your support.
My email address is: wedge.paul#gmail.com
To give it to you straight: No, there is no module that will do this. Largely because you have already made most content types and it is pretty unique to your project.
Still, you may not have limited programming skill, I would advice learning it when working with drupal. What you are asking is really not that hard to create by writing a custom module. Writing a custom module is really not that hard, and starting to write a custom module in Drupal is really well documented.
I can tell you what to use in the custom module, however it is better if you create it yourself (for future projects).
So you create your custom module:
function mymod_nodeapi{ //here all the action happens when a node is created
switch ($op) {
//if the node is inserted in the database
case 'insert':
//if node is a job application
if($node->type = "jobapplication"){
//using node_load function, you can load other nodes in a variable
$relatednode = node_load($node->nodereference);
//using drupal_mail function, you can mail people
drupal_mail();
}
break;
}
}
This code has not been tested and can't be copy pasted. However node_load and drupal_mail as well as hook_nodeapi... use those functions and you'll get there.
Lullabot's video tutorial "Learning CCK for Drupal" is based on the concept of a job application/posting site as a case study. It may be worth investigating.
no, I'm not connected in any way to Lullabot; just a fellow Drupaler