how can I add company logo in email in cakephp? - image

I have created page for mail template and set buttons for preview template also.
I have set image path from my local machine like,
src="/projectname/app/webroot/img/logo.JPG"
and when i preview that template it displays logo.
when using that template when i send mail image is not displayed in email.
So can anyone please tell me what could be the issuee or i am missing something like mime types?
Thanks,

This won't work. The email is opened in a client, what the hack would a path like "/projectname/app/webroot/img/logo.JPG" mean to that client? What is the domain?
You can either add a domain to the SRC like src="http://example.com/projectname/app/webroot/img/logo.JPG". But this won't be displayed by default, because it is a security risk.
Imagine spammers including images like src="http://example.com/feedback?id=12345" to each email, where ID is identifying each e-mail address the mail is sent to. Each client downloading this image will acknowledge the receiving of this e-mail, letting the spammers know you are reading their spam. Most e-mail clients explicitly ask you whether images referred to in the mail should be downloaded or not.
An alternative solution is to include each e-mail as an attachment to the e-mail, then you can refer to it as an "inline" image. This does no requires external connection and is less of a security risk, mostly allowed by default in clients.
I've google up a component that supposedly supports also inlining, but you might find others as well:
http://bakery.cakephp.org/articles/CraZyLeGs/2006/12/18/swiftmailer-component-tutorial

Within emails, you must use your full path, not a relative path. To do this easily in CakePHP, use the: FULL_BASE_URL constant with the HTML Helper like this:
<?php
echo $this->Html->image(
FULL_BASE_URL . $photo['Photo']['path'].$photo['Photo']['filename']
);
?>
(obviously this could be done in one line, but I broke it down for ease of reading on StackOverflow)

That's probably because when you test on your local machine, that path is fine. But if you send an email to yourself (say gmail) your browser will probably look for the image somewhere like http://mail.google.com/gmail/projectname/app/webroot/img/logo.JPG and will not find your image there.
So you'll need to set your image source to something like http://localhost/projectname/app/webroot/img/logo.JPG.

The email client needs the absolute path to the image; use the HTML helper to attach the full base:
<?= $this->Html->image("logo.JPG", array('fullBase' => true)) ?>
Note that the /projectname/app/webroot/img/ is not required when using the HTML helper.

If you are using CakePHP v1.2 or 1.3 (yes they are deprecated - but hey someone might find this useful) you will need to add a Content-ID header to the image to be attached to the email so you can refer to it via the cid when using it inline in the message. Open the email controller of the cake installation and add this line in the __attachFiles() method:
$this->__message[] = 'Content-ID: <' . basename($file) . '>';
You can then add the image in your template like so:
The attachfile method of email class in v1.2 & 1.3 only accepts paths and does not have the added functionalities of later version hence the "hack"

Related

How can i change the text in a "password forgot" email in Laravel?

In a Laravel project in the folder app/mail there is a file called WelcomeDogSchoolManager.php
In this file I can see the text that is being sent when a new user registers himself.
Within this file, I can see the following code:
#component('mail::button', ['url' => $passwordResetUrl])
Registreren
#endcomponent
Unfortunately, the developer left a mistake in the $passwordResetUrl (leaving it at "https://login..{domain}.nl" instead of the required "https://login.{domain}.nl"
This causes all my users being unable to register (unless they manipulate the URL).
Where in the Laravel Project can I search for the option to change the $passwordResetUrl?
I have no working knowledge of Laravel and am basically just searching through all the files on the server using Filezilla, trying to figure it all out. I got to this point, but have no idea how to proceed further.
Any tips are appreciated!
if your're using Laravel version lower then 6 then search for forget controller. It's basically inside that folder because email is triggered from that controller. Hopefully, you'll find the parameter which is passing to the WelcomeDogSchoolManager class.

How can I globally specify the From email header for the TeamCity email notifier?

I've set up a gmail account to use when sending email notifications from my TeamCity installation. The emails are being sent correctly, but I want to specify the From: header using their .ftl files. According to this page (under Supported Output Values), I can specify email headers. I've copied their <global#... block directly into a number of their template files, namely common.ftl, build_successful.ftl and it never works.
The block I added looks like this:
<#global headers>
From: Some Test <myteamcitytestnotreal#gmail.com>
</#global>
It doesn't do anything. Neither does their sample headers. Any help is appreciated.
You can specify the From: address via the UI under Administration > Email Notifier -> Send email messages from:.
This updates the value stored in the <TeamCity data directory>/config/_notifications/email/email-config.xml file.
I suspect overriding the From: address at the ftl template level is not a supported approach given that the above is the documented method; it might make for a good feature request in TC 9.0.

Send Email with pdf file as attachment in rhomobile

I want to send email using mailto tag with a single pdf file as attachment.
mailto tag opens the mail window with passed arguments like to and subject using:
Mail to Manager
But, attachments as a parameter isnt working.
Please suggest how to send pdf attachment in rhomobile.
Thanks
I think that you need to add the physical path to the PDF file for it to work (otherwise it may not know where the file is). This post on a forum says as follows:
The only problem is that this "mailto" command executes on the
client machine, therefore it tries to locate the attachment file by
a physical path, and not by a virtual path.
That is,
Using mailto:iudith.m#zim.co.il?subject=my report&body=see attachment&attachment="\myhost\myfolder\myfile.lis"
works ok, but only for local users (those connected to the same
network as the "myhost" machine).
Using mailto:iudith.m#zim.co.il?subject=my report&body=see attachment&attachment="http://myhost:myport/my_location_virtual_path/myfile.lis"
does not work, it does not recognize such a syntax as valid for
the attachment file.
In your case you would properbly need to look at this part of the Rhomobile docs (on file system access) to get the right path to your file.
EDIT:
From you comment I can see that you are trying to make it work on iOS (due to the iOS specific path).
In this discussion (from Rhomobile's Google Group) it is explained that mailto doesn't support attachments on iOS. It says as follows:
Don't know about other platforms, but you cannot do this on iOS. mailto: does not support attachments on iOS.
You can do it using a native API, MFMailComposeViewController.
This is a complete controller with UI, so you would have to write a Native View Extension to use it:
http://docs.rhomobile.com/rhodes/extensions#native-view-extensions
EDIT 2:
I've looked around and it seems that mailto doesn't support attachments on Android either. This is because Android supports the RFC 2368 mailto protocol, which doesn't include attachments. Here is a reference to the Android mailto url parser.
I would suggest that you do as suggested for iOS, write a native extension. I think this post would be relevant for you.

Servlet send image from server and save in client

I'm new and just developing on J2EE.
I am modifying an existing application (an OpenSource project).
I need to save an image on a client sent by the server, but I do not know how.
This activity must be done in a transparent manner without affecting the existing operation of the application.
From the tests done I get this error:
java.lang.IllegalStateException: getWriter () has Already Been Called for this response.
How should carry out this task, according to your own opinion?
How do I save on the client, locally, the image?
Update:
Thanks for the answers.
My problem is that:
the image is generated on the server, but not for direct client request (there is no link to click on web page), the picture is composed using other services on the Internet.
reconstruct the image on the server.
This image must be sent to the client to be saved locally.
so I'd like it to appear a window where you assign the destination image
plus I'd like the rest of the application were not affected by this activity.
The application is yet on production.
Thank you very much for your response.
From the tests done I get this error: java.lang.IllegalStateException: getWriter () has Already Been Called for this response.
In other words, you were trying to mix the binary data of the image with the character data of the HTML output, or you were trying to do this in a JSP instead of a Servlet. This is indeed not going to work. You need to send either the image or the HTML page exclusively in response to fully separate requests.
In your JSP/HTML page just have a link to the image, like so:
click to download image
Then, in a servlet listening on an url-pattern of /imageservlet/*, you just get the image as InputStream from some datasource (e.g. from local disk file system as FileInputStream) and then write it to the OutputStream of the response the usual Java IO way.
You only need to set at least the Content-Disposition response header to attachment to make sure that the client get a Save As popup dialogue, else it will be displayed straight in the browser. Setting the Content-Type and Content-Length are also important so that the browser knows what the server is sending and can predict how long the download may take.
response.setHeader("Content-Type", getServletContext().getMimeType(file.getName()));
response.setHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\"");
You can find complete basic servlet example in this article.
Note: you cannot control where the client would save the image, this would be a security hole. This way websites would be able to write malicious files on client's disk unaskingly.
Update: as per your update, there are two options:
You need to let the client itself fire two HTTP requests (I've answered this in your subsequent question)
Create a client side application which does all the task directly at the client side and then embed this in your webpage, for example a Java Applet. With an applet you have full control over the client environment. You can execute almost all Java code you'd like to execute and you can write files to disk directly without asking client for the location to save. You only need to sign the applet by a 3rd party company or the client needs to confirm a security warning before running.
Its up to the browser how all types of output are handled. Web pages are given a content type of html which the browser understands and ends up rendering ass a page that we can see. Images are given content type of image/jpeg etc which are rendered as images when in a page etc. To force a download prompt one needs to use a content type of a binary file rather than that of an image so the browser forces the download rather than shows the image. To ensure this use something like "application/octetstream"... i cant recall exactly but its easy to google for.

Using selenium in order to read emails on gmail

I'm using selenium-rc and I'm trying to click on a specific email on gmail in order to get into the email page. More specifically: on the gmail inbox, click on a email with a specific subject.
I can't find the correct xpath (none of the tags in the email part are links). Ideas?
This XPath should do the trick:
//div[#class = 'y6']/span[contains(., 'subject_here')]
... provided that you've first changed to the canvas_frame frame. Otherwise, it's unlikely it'll work at all. If you're not using Firebug to inspect the HTML, you really should as that's how I found out these values. Also, the Gmail structure changes fairly regularly, so that y6 class could change any day.
I haven't tested this, but this might work for you:
open http://gmail.com
// do the login stuff, click on login
waitForElementPresent canvas_frame
selectFrame canvas_frame
waitForElementPresent //div[#class = 'y6']/span[contains(., 'subject_here')]
clickAt //div[#class = 'y6']/span[contains(., 'subject_here')] 0,0
// do stuff you care about
Important: you have to use clickAt to cause Gmail to realize you're clicking. It doesn't work with just the simple "click" command.
By the way, we do this for our own internal monitoring of Gmail because it's been so unstable over the last few months. We're using my companies Selenium-based free monitoring service, which lets you run Selenium scripts to check performance and functionality of your site.
change gmail to basic html mode.
Is your app a Ruby on Rails one by chance? If so, email spec is a great way to test emails without haveing to mess around with Gmail: http://github.com/bmabey/email-spec
I used this command
clickAt | //table/tbody/tr/td[5]/div[#class='yW'] |
Click at the FROM field of first/recent/top most mail to go to mail detail page. // note: tr for first mail, tr[2] for second and so on.

Resources