How to add signature to powershell code creating new mail? - powershell

I want signatures to show up when creating new message as they do with Ctrl+N?
Here is my code:
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "random.dude#email.com"
$Mail.Subject = "data for Subject"
$Mail.Body ="Example of body..."
$Mail.Signature = "Primary"
$inspector = $mail.GetInspector
$inspector.Display()

You could refer to the below code:
$Signature = "`n`nBest Regards,`nYourName`nyour#email.com"
$Mail.Body = "Si comunica che i pacchetti harvest $esito.`nSi rimanda alle verifiche del caso `nSaluti$Signature"
For more information, Please refer to this link:
Powershell email signature

The signature is added when Display is called as long as the message body is unmodified.
This means you must call Display first, and then merge your data with the body that the message has at this moment.
Also keep in mind that to keep the signature formatting, you must use the HTMLBody property rather than plain text Body. And you cannot simply concatenate two HTML strings - they must be merged.
If using Redemption (I am its author) is an option, it exposes RDOSignature.ApplyTo method, which allows to insert signature into an existing message.

Related

Forward emails with PowerShell and EWS Managed API

I have a PowerShell Script that uses EWS Managed API to fetch and processes specific emails from an inbox. If an email doesn't meet a condition its then forwarded to another inbox. the script works fine, but if it finds emails with attachments (that don't meet condition), it gets stuck to Draft folder and doesn't get sent. Any ideas?
The part of the code that forwards the emails.
Else {
$mail = New-Object Microsoft.Exchange.WebServices.Data.EmailMessage($service)
$OriginalEmail = $findResults.Items[0]
$psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly)
$psPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::MimeContent)
$psPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject)
$OriginalEmail.Load($psPropset)
# Delete Received email after gathering the data
$findResults.delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::MoveToDeletedItems,$True)
$AtColtype = ("Microsoft.Exchange.WebServices.Data.AttachmentCollection") -as "Type"
$Emailtype = ("Microsoft.Exchange.WebServices.Data.EmailMessage") -as "Type"
$methodInf = $AtColtype.GetMethod("AddItemAttachment");
$AddItmAttachMethod = $methodInf.MakeGenericMethod($Emailtype);
$EmailAttachment = $AddItmAttachMethod.Invoke($mail.Attachments,$null);
$EmailAttachment.Item.MimeContent = $OriginalEmail.MimeContent
$PR_Flags = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(3591, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);
$EmailAttachment.Item.SetExtendedProperty($PR_Flags,"1");
$EmailAttachment.Name = $OriginalEmail.Subject;
$mail.Subject = "$Subject";
$mail.ToRecipients.Add($ForwardToEmail);
$mail.SendAndSaveCopy();
$mail.Close()
}
Any help is appreciated.

Create Outlook appointment on specific account with command line

I have 2 accounts in my outlook configured, one is for example foo.bar#test.com. When I try to create an appointment via commandline OUTLOOK.EXE /c ipm.appointment, the appointment dialog appears, but its not assigend one of my accounts.
I recognize that when I add participant and try to send the appointment. Then the following message appears (translated):
This appointment is not in the folder "Calendar" for this account. Responses to this appointment will not be recorded. Do you want to contiune?
How can I create an appointment which is assigend to the folder "Calendar" to one of the existing accounts?
You could refer to this code:
$fieldservices = "0000000038A1BB1005E5..."
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$calendar = $namespace.GetStoreFromID($fieldservices).GetDefaultFolder(9)
$appt = $Outlook.CreateItem(“olAppointmentItem”)
$root=$store.GetRootFolder()
$cal=$root.Folders.Item(5)
$appt.Move($cal)
#Making the appointment a meeting
$appt.MeetingStatus = 1
#Meeting one hour from current date and time
$appt.Start = $starttime
$appt.End = $appt.Start.AddMinutes($duration)
#Adding required attendees
$appt.RequiredAttendees = $tech
$appt.Subject = "$tech - $company: $summary - $ticket"
$appt.Location = "$address1 $address2 $city $zip"
$appt.Body = $body
$appt.Send()
For more information , Please reference this link:
Powershell Create Outlook Appointment

Zend Mail 1.12 setReturnPath

When i set the Return Path with setReturnPath, the e-mail header of the generated e-mail is different from the SET value (info#test.com). Is this an issue of Zend Framework 1.12.3?
Or can i fix it with another setting / header?
$mail = new Zend_Mail();
$mail->setBodyHtml($html);
$mail->setReplyTo('info#test.com');
$mail->setReturnPath('noreply#test.com');
$mail->setFrom('info#test.com', '...');
$mail->addTo(...);
$mail->setSubject(...);
$mail->send();
Have you thought about the order of the code.
This code is untested my or my not work.
//Create Zend_Mail object.
$MailObj = new Zend_Mail();
$message= "<h1>Welcome to the example</h1><br>" .
"<p>An example email.</p>";
//Initialize parameters.
$fromEmail = "FROM_EMAIL_ADDRESS";
$fromFullName = "FROM_FULL_NAME";
$to = "YOUR_EMAIL_HERE";
$subject = "This is an example";
$MailObj->setBodyHtml($message);
$MailObj->setFrom($fromEmail, $fromFullName);
$MailObj->addTo($to);
$MailObj->setSubject($subject);
$MailObj->setReplyTo('info#test.com');
$MailObj->setReturnPath('noreply#test.com');

how do i send an email through joomla

I have a system so folks can register for a class through my Joomla site (I believe it's 3.0). But from there, I would like to send folks an email filling variables from the registration. So something like:
Dear (name), thank you for registering for (class).
This is to remind you your class is tomorrow, (date), at (place).
I believe for the registration, the system uses authorize.net
How can I accomplish this?
Thanks for the help!!
You can use JFactory:getMailer like suggested in the following post. I'm copying here his code example (modified it a bit):
$subject = "Here is the subject of your message.";
$body = "Here is the body of your message.";
$user = JFactory::getUser();
$to = $user->email;
$from = array("me#mydomain.com", "Brian Edgerton");
# Invoke JMail Class
$mailer = JFactory::getMailer();
# Set sender array so that my name will show up neatly in your inbox
$mailer->setSender($from);
# Add a recipient -- this can be a single address (string) or an array of addresses
$mailer->addRecipient($to);
$mailer->setSubject($subject);
$mailer->setBody($body);
# If you would like to send as HTML, include this line; otherwise, leave it out
$mailer->isHTML();
# Send once you have set all of your options
$mailer->send();
That's all there is to it for sending a simple email. If you would like to add carbon copy recipients, include the following before sending the email:
# Add a blind carbon copy
$mailer->addBCC("blindcopy#yourdomain.com");
Another alternative is using JMail::sendMail: http://docs.joomla.org/API17:JMail::sendMail
Fetch the Mail Object:
`$mailer = JFactory::getMailer();`
Set a Sender
$user = JFactory::getUser();
$recipient = $user->email;
$mailer->addRecipient($recipient);
$mailer->setSender($sender);
Recipient
$user = JFactory::getUser();
$recipient = $user->email;
$mailer->addRecipient($recipient);
Create the Mail
$body = 'Body Text';
$mailer->isHtml(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
Sending the Mail
$send = $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ';
} else {
echo 'Mail sent';
}
https://docs.joomla.org/Sending_email_from_extensions

PHP mail to variable

I've searched and searched for something similar, but i think i'm not doing it right. So i will ask a question. This is very basic. My problem is as follows:
I have a multi-page form, consisting of 4 pages + 1 preview page. On the preview page, upon submitting i want the entire form data to be sent to 2 different mail adresses. One standard, and the other one, the one that the user has submitted.
So i have:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<?php
$email_from = 'mail#company.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "yourname#yourwebsite.com, $email /n";
$headers = "From: Company";
mail($to,$email_subject,$email_body,$headers);
?>
How should I insert the submitted $email variable in order for it to work?
Remove the \n
$to = 'yourname#yourwebsite.com,' . $visitor_email;
According to the mail() function documentation the $to parameter will take a comma-separated list of addresses as you have attempted, but should have no line break at the end.
Also, your variable is $visitor_email, rather than $email.
$to = "yourname#yourwebsite.com, $visitor_email";
You might also consider adding the visitor's email as a CC or BCC rather than the TO address. In that case, add it as a CC or BCC header (separated by \r\n), but you need to be cautious to be sure that the address is an email address and contains no line break characters which could be used for header injection.
// The From should be an email address
$headers = "From: company#example.com\r\n";
$headers .= "CC: $visitor_email;