Get SenderEmailAddress from mail item in compose mode - email

I am retrieving, this mailItem in compose mode, But when I check for the mailItem.SenderEmailAddress, it is NULL, but all other properties have values there (Ex:- body, body format, to, .... ). How I get the sender email FROM THE MAIL-ITEM IT-SELF?
I am using Visual Studio 2013 with Addin express v.7.7.4087
Here is the code :-
Outlook.Inspector currentInspector = null;
Outlook.MailItem mailItem = null;
Outlook.Folder outboxFolder = null;
Outlook.Recipients recipients = null;
const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
currentInspector = Globals.ObjOutlook.ActiveInspector();
if (currentInspector != null)
{
if (currentInspector.CurrentItem is Outlook.MailItem)
{
mailItem = currentInspector.CurrentItem as Outlook.MailItem;
mailItem.Save();
string sender = mailItem.SenderEmailAddress; //This is null
}
}
P.S
I have to deal with multiple mail boxes. so, I can't get current users address using Namespace. It always return me the address of primary mail box user.
Please see following screen shot
Thanks in advance.
Kushan Randima

Are you sending using multiple Exchange accounts? Use MailItem.SendUsingAccount, then read Account.SmtpAddress. If it is "", use Account.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress.
If MailItem.SendUsingAccount == null, you can assume the default account.

Use the CurrentUser property of the Namespace class to get the currently logged-on user as a Recipient object. The Address property of the Recipient class returns a string representing the e-mail address of the Recipient.

Related

Error in processing inbound mail in Apex Email Services

I have cretaed an Emaail service and associated an Apex class with it. The Apex class does a simple job of checking the subject of the mail and insert a record in the contact object, if the suject matches witha particular string. The last name of the contact is extracted from the inbound mail body.
The code is as follows:
global class CreateContactFrmEmail implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
String subToCompare = 'Create Contact';
if(email.subject.equalsIgnoreCase(subToCompare))
{
Contact c = new Contact();
c.LastName = email.plainTextBody;
insert c;
}
result.success = true;
return result;
}
}
However, whenever I send a mail to the generated email address, it is unable to create the contact, the mail bounces and the following exception is reported.
Any help in this regard is appreciated. TIA.

Leverage Groups for Workflow Approvals

We're implementing a new workflow (combined with staging task sync) on an existing website where we would like to notify all members that "own" that particular section/content to approve changes.
One of the options is to have multiple roles and their corresponding workflows configured for their role and scope, but this seems like overkill - at least for us, as currently one single role is set for approvals (and another for editors)
However I've recently come across this new page property:
And have a couple of questions:
Can regular CMS users (without membership) be part of a group?
Would we be able to leverage this group for the workflow's email notifications instead of the roles? E.g. email to everyone in the owner group when a page was sent for approval.
Is this option by default inherited from the parent page when a new one is created or does it need to be set individually for each page?
We have a Kentico 11 EMS license and working on an advanced workflow, therefore custom code is possible.
Can regular CMS users (without membership) be part of a group?
- why don't you use roles here?
Would we be able to leverage this group for the workflow's email
notifications instead of the roles? E.g. email to everyone in the
owner group when a page was sent for approval.
- you'll need to customize workflow manager class, but in general yes, it is possible. You could find an inspiration in this post
Is this option by default inherited from the parent page when a new
one is created or does it need to be set individually for each page?
- Use a macro to default the field. If you populate it with anything else then the new values will be saved.
Sample code snippet for Custom Global Event Handler for Workflow steps i.e., Reject and Approve steps.
using CMS;
using CMS.Base;
using CMS.DataEngine;
using CMS.DocumentEngine;
using CMS.EmailEngine;
using CMS.EventLog;
using CMS.Helpers;
using CMS.MacroEngine;
using CMS.SiteProvider;
using CMS.WorkflowEngine;
using System;
// Registers the custom module into the system
[assembly: RegisterModule(typeof(CustomWorkflowEvent))]
public class CustomWorkflowEvent : CMSModuleLoader
{
// Module class constructor, the system registers the module under the name "CustomInit"
public CustomWorkflowEvent()
: base("CustomInit")
{
}
// Contains initialization code that is executed when the application starts
protected override void OnInit()
{
base.OnInit();
// Assigns custom handlers to events
// WorkflowEvents.Approve.After += WorkFlow_Event_After();
WorkflowEvents.Reject.After += WorkFlow_Event_After;
WorkflowEvents.Approve.After += Approve_After;
// WorkflowEvents.Action.After += WorkFlowAction_Event_After;
}
private void Approve_After(object sender, WorkflowEventArgs e)
{
try
{
WorkflowStepInfo wsi = e.PreviousStep;
if (wsi != null)
{
CMS.WorkflowEngine.Definitions.SourcePoint s = wsi.GetSourcePoint(Guid.NewGuid());
//Make sure it was an approval (standard) step
var approvers = WorkflowStepInfoProvider.GetUsersWhoCanApprove(wsi, null, SiteContext.CurrentSiteID, "UserID = " + CMSActionContext.CurrentUser.UserID, "UserID", 0, "Email, FullName, Username");
EventLogProvider.LogInformation("Approvers Data", "Approvers Data", approvers.ToString());
if (approvers != null)
{
//Loop through the approvers
string siteName = null;
SiteInfo si = SiteInfoProvider.GetSiteInfo(SiteContext.CurrentSiteID);
if (si != null)
{
siteName = si.SiteName;
}
EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate("Workflow.Rejected", SiteContext.CurrentSiteName);
MacroResolver mcr = MacroResolver.GetInstance();
EmailMessage message = new EmailMessage();
// Get sender from settings
message.EmailFormat = EmailFormatEnum.Both;
message.From = eti.TemplateFrom;
// Do not send the e-mail if there is no sender specified
if (message.From != "")
{
// Initialize message
// message.Recipients = strRecipientEmail;
message.Subject = eti.TemplateSubject;
// Send email via Email engine API
// EmailSender.SendEmailWithTemplateText(SiteContext.CurrentSiteName, message, eti, mcr, true);
}
}
}
}
catch (Exception ex)
{
throw;
}
}
private void WorkFlow_Event_After(object sender, WorkflowEventArgs e)
{
try
{
WorkflowStepInfo wsi = e.PreviousStep;
if (wsi != null)
{
CMS.WorkflowEngine.Definitions.SourcePoint s = wsi.GetSourcePoint(Guid.NewGuid());
//Make sure it was an approval (standard) step
var approvers = WorkflowStepInfoProvider.GetUsersWhoCanApprove(wsi, null, SiteContext.CurrentSiteID, "UserID = " + CMSActionContext.CurrentUser.UserID, "UserID", 0, "Email, FullName, Username");
EventLogProvider.LogInformation("Approvers Data", "Approvers Data", approvers.ToString());
if (approvers != null)
{
//Loop through the approvers
string siteName = null;
SiteInfo si = SiteInfoProvider.GetSiteInfo(SiteContext.CurrentSiteID);
if (si != null)
{
siteName = si.SiteName;
}
EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate("Workflow.Rejected", SiteContext.CurrentSiteName);
MacroResolver mcr = MacroResolver.GetInstance();
EmailMessage message = new EmailMessage();
// Get sender from settings
message.EmailFormat = EmailFormatEnum.Both;
message.From = eti.TemplateFrom;
// Do not send the e-mail if there is no sender specified
if (message.From != "")
{
// Initialize message
// message.Recipients = strRecipientEmail;
message.Subject = eti.TemplateSubject;
// Send email via Email engine API
// EmailSender.SendEmailWithTemplateText(SiteContext.CurrentSiteName, message, eti, mcr, true);
}
}
}
}
catch (Exception ex)
{
throw;
}
}
}
Hope Helps you.
Can regular CMS users (without membership) be part of a group?
It is not part of CMS users. Groups are coming from Groups Application.
GROUP: Allows you to manage user groups. Groups are a social networking
feature enabling users to find information and communicate according
to shared interests.
Would we be able to leverage this group for the workflow's email notifications instead of the roles? E.g. email to everyone in the owner group when a page was sent for approval.
No
Is this option by default inherited from the parent page when a new one is created or does it need to be set individually for each page?
No

Play Framework [play-mailer]: how to ensure each receiver sees only his or her email address in the TO field

Here below is the code to send an email with play-mailer:
import play.api.libs.mailer._
...
val email = Email(
"My Subject",
"Me <j3d#domain.com>",
Seq("john#domain.com", "joe#domain.com", "jack#domain.com"),
bodyText = Some("Some text..."),
bodyHtml = Some("<p>Some text...</p>")
)
MailerPlugin.send(email)
The problem is that receivers see all the recipients the email was sent to. Of course, an option could be to invoke MailerPlugin.send for every single recipient... but I'm wondering if there is a better way to ensure each receiver sees only his or her email address in the to field.
Perhaps the best solution will be using hidden recepient which aka BCC. Emailer plugin has method addBcc(String address):
public void addBcc(String address) {
this.bcc.add(address);
}
Regards!

AE.net.Mail, How to move mail to a new folder in outlook

How to move mail to a new folder in outlook?
My code:
using (ImapClient ic = new ImapClient(
imapAddr,
myEmailID,
myPasswd,
ImapClient.AuthMethods.Login,
portNo,
secureConn))
{
ic.SelectMailbox("INBOX");
bool headersOnly = false;
Lazy<MailMessage>[] messages = ic.SearchMessages(SearchCondition.Unseen(), headersOnly);
foreach (Lazy<MailMessage> message in messages)
{
MailMessage m = message.Value;
}
}
I try Google it but I can not find it .
Any suggestions are highly appreciated.
to move a message to another folder do this:
ic.MoveMessage(message.Uid, "some existing folder");
The uid is the unique identifiier for the mailmessage. I assume it maps to the message-id as described in RFC for Internet Message Format. Or otherwise to the UNIQUEID in the IMAP protocol.
to create a new folder use the this method:
ic.CreateMailbox("new mailbox name");
To send emails use an SmtpClient, like the one that is supplied in the .net framework:
using(SmtpClient client = new SmtpClient("your smtp server.com"))
{
client.Send("from#example.com",
"to#example.com",
"subject",
"Hello World");
}

Java send mail - how to use "Send via"

We are sending mails from our local system.
We got our IPs white listed.
We have a scenario where we have to send email on behalf of somebody.
for ex: our email id is: support#mycompany.com
but we need to send email with a from address: john#abc.com
When we send with different from address, the receiving mail client displays "phishing" error.
One of the solution is to use "via" as dispayed in google link
https://mail.google.com/support/bin/answer.py?hl=en&ctx=mail&answer=185812
We also want the message to be displayed like this in receivers inbox.
Any pointers in this will help us a lot.
thanks in advance.
Note: We are using localhost as the smtp.
Read about email headers. you can add email headers while creating the mail message at runtime.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.jcom.net");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
for further reading check this :
http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274
http://javamail.kenai.com/nonav/javadocs/javax/mail/internet/package-summary.html
#http://javamail.kenai.com/nonav/javadocs/javax/mail/internet/MimeMessage.html
You can create aliases for the smtp server too.