I am trying to sort out current contacts in Outlook to replace encryption certificates. But it is not clear how to prepare the object?
# В var $contactList collect contacts from Outlook
foreach ( $name in $contactList ) {
$PR_x509_Certificate = ('http://schemas.microsoft.com/mapi/proptag/0x3A701102');
# Create new contact
$NewContact = $Outlook.CreateItem('olContactItem');
# Get email, name, fullname from old contact
$NewContact.Email1Address = $name.Email1Address;
$NewContact.FullName = $name.FullName;
$NewContact.FirstName = $name.FirstName;
# Import certificate from из .cer file
$NewCertUser = New-Object system.security.cryptography.x509certificates.x509certificate2;
$NewCertUser.Import($PathToCerFile);
# Try add sertificate, but no success :(
$result = $NewCertUser.RawData;
$o = New-Object BuildProperty($result);
$NewContact.PropertyAccessor.SetProperty($PR_x509_Certificate, $o);
# Save new contact
$NewContact.Save();
# Delete old
$name.Delete();
}
I'm trying to update this:
It should be possible to do that on the users certificate store certmgr.msc without even touching Outlook:
Related
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.
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
Does anyone know as how can I make a mail in perl using outlook and not send it just open it on the screen at the end of making the mail and let the user verify and send the mail. I am using Win32::OLE for making the mail.
PFB the code I am using:
sub Final_Mail_Outlook{
my($mailTo,$mailFrom,$subject,$body) = (#_);
my $Outlook = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application');
# Create Mail Item
my $item = $Outlook->CreateItem(0); # 0 = mail item.
unless ($item)
{
die "Outlook is not running, cannot send mail.\n";
}
$item->{'Subject'} = $subject;
$item->{'To'} = $mailTo;
$item->{'Body'} = $body;
$item->{'From'} = $mailFrom;
my $attach = $item->{'Attachments'};
my #outputFiles = glob("$OutputPath\\*.*");
foreach my $file (#outputFiles){
$attach->add($file);
}
$item->Send();
}
This sends the mail as I have called Send function, but I want to verify the mail generated. So is there a way to do so???
I just found an answer to it so thought of posting it also so that someone else needing an answer to this can get help. The key is to use the function Display() instead of Send(). PFB the modified code to open the mail and not send it.
sub Final_Mail_Outlook{
my($mailTo,$mailFrom,$subject,$body) = (#_);
my $Outlook = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application');
# Create Mail Item
my $item = $Outlook->CreateItem(0); # 0 = mail item.
unless ($item)
{
die "Outlook is not running, cannot send mail.\n";
}
$item->{'Subject'} = $subject;
$item->{'To'} = $mailTo;
$item->{'Body'} = $body;
$item->{'From'} = $mailFrom;
my $attach = $item->{'Attachments'};
my #outputFiles = glob("$OutputPath\\*.*");
foreach my $file (#outputFiles){
$attach->add($file);
}
$item->Display();
}
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
I have a question about how to add users to AD using powershell, ive written a small script but i always get an error when i try to create a user.
$connection= "LDAP://ou=Users, dc="domain", dc="com"
$OU = [adsi] $Connection
$User = $OU.Create("user", "Test Person")
$User.Put("Firstname", "Test")
$User.Put("Surname", Person)
$User.Put("Email", "email#e.com")
$User.SetInfo()
I think my connection string is wrong, but i tried different ways already and still no success. This im trying locally. Need to get it working but then normally my AD is on different server, how to do it then?
Thanks in advance.
Give this a try:
$container = [ADSI] "LDAP://dc.sopragroup.lan/cn=Users,dc=sopragroup,dc=lan"
$UserName = "user"
$User = $container.Create("User", "cn=" + $UserName)
$User.Put("sAMAccountName", $UserName)
$User.Put("givenName", "Test")
$User.Put("sn", "Person")
$User.Put("mail", "email#e.com")
$User.SetInfo()
$User.psbase.InvokeSet('AccountDisabled', $false)
$User.SetInfo()
$User.SetPassword("P#55w0rd")
Here is another example (#Andy Arismendi was first) with some other details:
If you want to give a user and a password (log onto the server with a different user than the current one), you can use the DirectoryEntry constructor
An error that is commonly done is that when you create an object in a directory, the name that represent this object in the directory tree is built with the construction : attribute=value. In Active-Directory you can't choose the the attribute it's imposed by the schema. For a user or an inetOrgPerson it's CN for an organizationalUnit it's OU. In your case the name of the object is CN=Test Person.
You'll find here under the creation of an OU and a user.
Clear-Host
$dn = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://192.168.234.200:389/dc=dom,dc=fr","administrateur#dom.fr","admin")
# Create an OU
$Monou = $dn.create("OrganizationalUnit", "ou=Monou")
#$Monou.Description = "Une description"
$Monou.put("Description", "Une description")
$Res = $Monou.Setinfo()
# Create a user
$objUtilisateur = $Monou.create("inetOrgPerson", "cn=Marc Assin")
$objUtilisateur.setinfo()
$objUtilisateur.samaccountname = "Massin"
$objUtilisateur.givenName = "Marc"
$objUtilisateur.sn = "Assin"
#$objUtilisateur.displayName = $objUtilisateur.givenName + " " + $objUtilisateur.sn
$objUtilisateur.userPrincipalName = "Massin#dom.fr"
# Pu the state of the account#$objUtilisateur.SetPassword("test.2010")
$objUtilisateur.pwdLastSet = 0
$objUtilisateur.userAccountControl = 544
# Write the datas of the user
$objUtilisateur.SetInfo()