everyone. I am trying to send email with attachment on it. What I have done is :
controller code snippet:
try{
Mail::send(['name' => 'By System'],array(), function($msg) use ($email,$name,$message,$attachment,$ext,$display) {
$msg->from('ricket999#gmail.com', 'Markle Admin');
$msg->to($email)->subject('Payment Done')
->setBody('This is to notify you that the employee named '.$name.' has been paid for the monthly payment. Thank You.','text/html')
->attach(public_path().'/'.$attachment, ['as' => $display.'.'.$ext, 'mime' => 'application/pdf']); });
}
catch(Exception $e){
// if any error mark the mail sent status 0
$result = DB::table('message')->where('name',$name)->where('email',$email)->update(['sent'=>'0']);
}
But it is showing this error :
Type error: Argument 1 passed to Swift_Mime_SimpleMessage::attach() must implement interface Swift_Mime_MimeEntity, string given, called in E:\xampp\htdocs\email-send\app\Http\Controllers\HomeController.php on line 133
What have I missed. I saw this and this but it is same as mine and they say its working but why am I getting this error. Any kind of help are appreciated. Thank you.
You have 2 problems:
You are trying to attach a zip archive while you have set the mime as application/pdf
The path to your archive is wrong.
Instead of
E:\\xampp\\htdocs\\email-send\\public\\files\\1520764563.zip it is E:\\xampp\\htdocs\\email-send\\public/files/1520764563.zip
Regarding the Argument 1 passed to Swift_Mime_SimpleMessage::attach() must implement interface Swift_Mime_MimeEntity, string given error I suppose that this solves your problem:
$swiftAttachment = Swift_Attachment::fromPath($correctPath);
$this->email->attach($swiftAttachment); // now attach the correct type
Related
so I'm wanting to make this form where the client fills their name, email and a message. Then that message and their name is sent to my mail address and another mail is sent from my address to the clients one telling that their mail was sent successfully.
I already did this on another project and literally just copied changing the name of the functions n stuff but it doesn't work.
views.py
def send_email(email):
context = {'email': email}
template = get_template('emails/message-confirmation.html')
content = template.render(context)
email = EmailMultiAlternatives(
'Test email',
'AmiSalta message confirmation',
settings.EMAIL_HOST_USER,
[email]
)
email.attach_alternative(content, 'text/html')
email.send()
def function(request):
form = ContactForm_es()
if request.method == 'POST':
email = request.POST.get('email')
send_mail(email)
form = ContactForm_es(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
full_name = form.cleaned_data['full_name']
body = form.cleaned_data['body']
send_mail(full_name,body,email, ['******#gmail.com'])
return render(request, 'es/home.html', {
'form': form,
})
I'm going crazy bc is the last thing I need to do and I already did once but I just can't make it work. Please if someone knows what's wrong let me know, thanks in advance.
I was getting the same issue you are having and the thing I was doing wrong was in the URLs.py file I was calling send_mail directly instead of the veiw_func that sends the mail that is why it was saying all the three required parameters are missing.
check your URLs.py file you might be having the same issue
Check if you use your send_email in urls.py instead of send_mail. The name of your function is very similar to the django's send_mail() function. You can easily confuse yourself.
Change the name of function def send_email(email): to something def mailtest(email):
you are getting thise error beacause
you are trying to overwrite the function
We are developing a Gmail Addon in which we extend the compose UI.
This extends the compose window in which you can compose your e-mail.
We need the 'From', 'To', 'Subject' and 'Body' of the message that is being composed.
The 'From' can be read from the Session object like this
var mySelf = Session.getEffectiveUser().getEmail();
The 'To' can be read from the draftMetadata from the event object of the function being called.
function composeEmail(event) { console.log(event.draftMetadata.toRecipients); }
The 'Subject' and 'Body' can't be read from the event object of the function since it is a composeTrigger. The argument contains these objects:
{
formInput = {},
clientPlatform = web,
formInputs = {},
parameters = {},
draftMetadata = {
toRecipients = [test #test.com],
subject = ,
bccRecipients = [],
ccRecipients = []
}
}
Surprisingly to me, the subject key is there but not being filled in (yes I did type in a subject).
Question:
How can I get the 'Subject' and 'Body' of the E-mail being composed by the user in the extended composer UI?
Extra information:
The contextual trigger action contains the following object as event object:
{
clientPlatform = web,
messageMetadata = {
messageId = 16e agg7323451256989f68,
accessToken = AAGdOAawdaAOW8PWchmdawdk0N13STKnBPMAOXVjZVHyQMfAawdBtgEIrS6N8y5h2BOZnKFPlfsl5VBsyPiF7YiONOoP7XVjKZawdi - E6vI - jVU92dPmfj3RNmXfawdawdeaNMrXehAFLm
}
}
By reading an email through the contextual trigger a messageId is being added in which the getBody and getSubject methods can be used.
As of now, the Compose Trigger Event never returns the value of the subject field.
I have filled a bug for this here. Click the ★ icon to follow this Issue and get updates. This will also help prioritize this Issue.
As a workaround, you can use the contextual trigger to:
Get the messageId
Find drafts that have that messageId associated to them
Get the draft by their draftId
Fetch the subject line from the Headers object on the draft.
This only works on drafts that are replying to a specific message.
I've never done this before so this is a guess. I looked at the compose dialog html with the developer tools and this is what I noticed.
There seem to be a bunch of hidden inputs that are used to store values that are typed into the compose dialog. So I would try something like:
formInputs.body or perhaps formInput.body taking the name of the key from names of this hidden elements. This is just a guess.
I'm using the system extension form for small contact forms. The default success message is
The form has been sent successfully by mail
How can this message and the error message be changed and/or translated?
Edit your form content element, go to tab Form. There you will see the form configuration. In block postProcessor add a message block:
postProcessor {
1 = mail
1 {
recipientEmail = contact#example.com
senderEmail = form#example.com
subject = Call me please
messages {
success = Thank you! We will call you soon.
error = Oops! Something went wrong.
}
}
}
I've setup a form using googledocs. I just want to have the actual data entered into the form emailed to me, as opposed to the generic response advising that the form has been completed.
I have no skill or experience with code etc, but was sure i could get this sorted. I've spent hours+hours and haven't had any luck.
My form is really basic.it has 5 fields. 4 of which are just text responses, and one multiple choice.
I found this tute online (http://www.labnol.org/internet/google-docs-email-form/20884/) which i think sums up what i'm trying to do, but have not been able to get it to work.
from this site i entered the following code:
function sendFormByEmail(e)
{
var email = "reports.mckeir#gmail.com";
var subject = "Google Docs Form Submitted";
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
for(var i in headers)
message += headers[i] + ' = '+ e.namedValues[headers[i]].toString() + "\n\n";
MailApp.sendEmail(email, subject, message);
}
To this, i get the following response: ->
Your script, Contact Us Form Mailer, has recently failed to finish successfully. A summary of the failure(s) is shown below. To configure the triggers for this script, or change your setting for receiving future failure notifications, click here.
The script is used by the document 100% Club.
Details:
Start Function Error Message Trigger End
12/3/12 11:06 PM sendFormByEmail TypeError: Cannot call method "toString" of undefined. (line 12) formSubmit 12/3/12 11:06 PM
Is anyone able to help shed some light on this for me? I'm guessing i'm not including some data neeeded, but i honestly have no clue.
Workaround http://www.labnol.org/internet/google-docs-email-form/20884/
You have to setup app script to forward the data as email.
I'll point to the comment above that solved it for me: https://stackoverflow.com/a/14576983/134335
I took that post a step further:
I removed the normal notification. The app script makes that generic text redundant and useless now
I modified the script to actually parse the results and build the response accordingly.
function sendFormByEmail(e)
{
var toEmail = "changeme";
var name = "";
var email = "";
// Optional but change the following variable
// to have a custom subject for Google Docs emails
var subject = "Google Docs Form Submitted";
var message = "";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
// Credit to Henrique Abreu for fixing the sort order
for(var i in headers) {
if (headers[i] = "Name") {
name = e.namedValues[headers[i]].toString();
}
if (headers[i] = "Email") {
email = e.namedValues[headers[i]].toString();
}
if (headers[i] = "Subject") {
subject = e.namedValues[headers[i]].toString();
}
if (headers[i] = "Message") {
message = e.namedValues[headers[i]].toString();
}
}
// See https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(String,String,String,Object)
var mailOptions = {
name: name,
replyTo: email,
};
// This is the MailApp service of Google Apps Script
// that sends the email. You can also use GmailApp here.
MailApp.sendEmail(toEmail, subject, message, mailOptions);
// Watch the following video for details
// http://youtu.be/z6klwUxRwQI
// By Amit Agarwal - www.labnol.org
}
The script utilized in the example is extremely generic but very resilient to change because the message is built as a key/value pair of the form fields submitted.
If you use my script you'll have to tweak the for loop if statements to match your fields verbatim. You'll also want to edit the toEmail variable.
Thanks again for the question and answers. I was about to ditch Google Forms as the generic response was never enough for what I was trying to do.
Lastly, in response to the actual problem above "toString of undefined" specifically means one of the form fields was submitted as blank. If I had to guess, I would say the author only used this for forms where all the fields were required or a quick undefined check would've been put in place.
Something like the following would work:
for(var i in headers) {
var formValue = e.namedValues[headers[i]];
var formValueText = "";
if (typeof(formValue) != "undefined") {
formValueText = formValue.toString();
}
message += headers[i] + ' = '+ formvalueText + "\n\n";
}
I haven't tested this precisely but it's a pretty standard way of making sure the object is defined before trying methods like toString() that clearly won't work.
This would also explain Jon Fila's answer. The script blindly assumes all of the header rows in the response are sent by the form. If any of the fields aren't required or the spreadsheet has fields that are no longer in the form, you'll get a lot of undefined objects.
The script could've been coded better but I won't fault the author as it was clearly meant to be a proof of concept only. The fact that they mention the replyTo correction but don't give any examples on implementing it made it perfectly clear.
If this is a Google Form, do you have any extra columns in your spreadsheet that are not on the form? If you delete those extra columns then it started working for me.
You don't need to use a script. Simply go to Tools >> Notification Rules on your Google Spreadsheet. There you can change the settings to receive an email with your desired information every time the document is changed.
For my code, I retrieve an unread message from exchange, do some processing based on that message, and then reply to the message with the results of the processing I did.
The problem that I'm having is that when I attempt to reply to the email I'm getting the below error on calling responseMessage.send() or responseMessage.sendAndSave():
The current ChangeKey is required for this operation.
Below is the code that I am running that is triggering this error:
public void replyToEmail(EmailMessage _emailMessage, String _reply)
{
String serviceManager = emailServerAddress = ConfigurationSettings.AppSettings["serviceManagerEmail"].Trim();
ResponseMessage responseMessage = _emailMessage.CreateReply(true);
responseMessage.BodyPrefix = _reply;
String changekey = _emailMessage.Id.ChangeKey;
if (!serviceManager.Equals(""))
{
responseMessage.CcRecipients.Add(new EmailAddress(serviceManager));
}
responseMessage.Send();
}
I'm able to check the _emailMessage changeKey value via _emailMessage.id.Changekey and there is a value there, I would have expected that to be assigned to the responseMessage when _emailMessage.createReply() was call. I'm unable to find a way to manually assign it.
I've been unable to find any references to this issue during searching, I was hoping someone
I ran into this problem with .Forward, after setting the message IsRead = true and saving that update back to the server. That changes the ChangeKey, so it's no longer valid.
Try doing _emailMessage.Load() to get the message from the server again, and the new ChangeKey.