Currently a piece of our application creates and saves new mail messages to a user's drafts folder using Exchange Web Services. We would like to automatically append the user's default signature to these messages when creating them, but I have not been able to find a way to access the signature to append it to the body. The email message is currently created with the following code:
CreateItemType createEmailRequest = new CreateItemType();
createEmailRequest.MessageDisposition = MessageDispositionType.SaveOnly;
createEmailRequest.MessageDispositionSpecified = true;
DistinguishedFolderIdType draftsFolder = new DistinguishedFolderIdType();
draftsFolder.Id = distinguishedFolderIdNameType;
createEmailRequest.SavedItemFolderId = new TargetFolderIdType();
createEmailRequest.SavedItemFolderId.Item = draftsFolder;
MessageType emailMessage = new MessageType();
emailMessage.Subject = subject;
emailMessage.Body = new BodyType();
emailMessage.Body.BodyType1 = bodyType;
emailMessage.Body.Value = body;
emailMessage.Sensitivity = SensitivityChoicesType.Normal;
emailMessage.SensitivitySpecified = true;
createEmailRequest.Items = new NonEmptyArrayOfAllItemsType();
createEmailRequest.Items.Items = new ItemType[1];
createEmailRequest.Items.Items[0] = emailMessage;
Any ideas on how to get the current user's default signature and append it to the body the email?
The signatures in Outlook are a client-side feature and thus can't be accessed from Exchange Web Services. In fact I believe the signatures are actually stored in the users profile on the machine - I know I have to redo my signature when moving from one machine to another (I'm on Outlook/Exchange 2010).
In Exchange 2010 You can create a transport rule that can access user information, but there's not a way to use the Outlook signature information that I'm aware of.
Related
I have been using the "Shared Envelopes" feature to allow specific users who are not the sender or a recipient of the envelope to be able to view an envelope in my application without any issues. I used the following instructions to do so:
How to embed the DocuSign UI in your app:
https://developers.docusign.com/docs/esign-rest-api/how-to/embed-ui/
This lays out using the SDK method Envelopes::createConsoleView.
However, DocuSign has deprecated "Shared Envelopes" in favor of their new "Shared Access".
I removed the users from the "Shared Envelopes" of the sending account and added them to "Shared Access" of the sending account. Unfortunately, when I make this change the users can no longer view the envelope and receive the following error message:
Error calling CreateConsoleView: {"errorCode":"USER_NOT_ENVELOPE_SENDER_OR_RECIPIENT","message":"This user is not the sender or a recipient of the envelope. Only the sender or a recipient of the envelope may perform the requested operation."}
Here is my code:
//API - EnvelopeViews:createConsoleView
public string GetEnvelopeViewUrl(string accountId, string envelopeId, string returnUrl)
{
var token = _tokenService.FetchToken(accountId);
var apiClient = new DocuSignClient($"{token.Account.BaseUri}/restapi");
apiClient.Configuration.DefaultHeader.Add("Authorization", $"Bearer {token.Value}");
var envelopesApi = new EnvelopesApi(apiClient);
var apiAccountId = _config["DocuSign:ApiAccountId"];
ConsoleViewRequest viewRequest = new ConsoleViewRequest
{
EnvelopeId = envelopeId,
ReturnUrl = returnUrl
};
var recipientView = envelopesApi.CreateConsoleView(apiAccountId, viewRequest);
return recipientView.Url;
}
I know the users in my app are not the sender or a recipient of the envelope. I thought that was the whole point of "Shared Access". Can anyone provide some guidance on how to enable the new "Shared Access" users to be able to view an envelope like they can with the old "Shared Envelopes" in my application?
Baxter, as of right now (November 2022) the new feature for Shared Access is only to support using the web app and does not provide any functionality for developers using the API.
The old feature, like you mentioned, called shared envelopes, was fully supporting the API and the call you made would work with that.
There's a future plan to support the API using Shared Access, but I don't know the details or the date. I can update this answer once I have this information.
I am trying to create a rule by using EWS API for a shared mailbox. For that I am using the following code:
Rule newRule = new Rule();
newRule.DisplayName = "Forward";
forwardEmailTo= "xxx#hotmail.com";
newRule.Conditions.SentToAddresses.Add("Forward", "sharedmailbox#myexchangedomain.online");
newRule.Actions.ForwardToRecipients.Add(forwardEmailTo);
CreateRuleOperation createMoveIfFromSalesRule = new CreateRuleOperation(newRule);
service.UpdateInboxRules(new RuleOperation[] {createMoveIfFromSalesRule}, true);
But unfortunately the rule is not created on the shared mail box (sharedmailbox#myexchangedomain.online), it is being created on the principal mail box account.
What Am I doing wrong?
The UpdateInboxRules Method has an overload for the Mailbox you want to create the rule in so your method call should be
service.UpdateInboxRules(new RuleOperation[] {createMoveIfFromSalesRule,"TargetMailbxo#domain.com"}, true);
private async void sendMail(string from,string to, string subject,string text)
{
// Create network credentials to access your SendGrid account
string username = "xx";
string pswd = "xx";
MailMessage msg = new MailMessage();
NetworkCredential credentials = new NetworkCredential(username, pswd);
// Create the email object first, then add the properties.
// Create the email object first, then add the properties.
SendGridMessage myMessage = new SendGridMessage();
myMessage.AddTo("xx");
myMessage.Subject = "Testing the SendGrid Library";
myMessage.Text = "Hello World!";
myMessage.From = new MailAddress(from);
// Create an Web transport for sending email.
var transportWeb = new SendGrid.Web(credentials );
// Send the email.
await transportWeb.DeliverAsync(myMessage);
}
My application is Windows Phone 8.1, I try to send mail via sendGrid I created an account and include libraries to code but it gives 3 error:
error CS0570: 'SendGrid.SendGridMessage.From' is not supported by the language
error CS1502: The best overloaded method match for 'SendGrid.Web.Web(string)' has some invalid arguments
error CS1503: Argument 1: cannot convert from 'System.Net.NetworkCredential' to 'string'
I have used this site"https://azure.microsoft.com/tr-tr/documentation/articles/sendgrid-dotnet-how-to-send-email/" as reference.
Do errors stem from because app is a Windows Phone app or what?
And is there any other way to send an email by declaring "from" within code?
This isn't really an answer to your question, but it's important enough I made it an answer and not a comment.
This is not a secure way to send email from a mobile device, because you are giving the code that contains the credentials to users that install. All they need to do is inspect the traffic from your app and your SendGrid API key or account is compromised.
You need to make a request to some secure backend server (or provider, e.g. Parse or Azure), and then send the email from that server rather than the client app.
If you want to debug the code though, check out the readme and example on Github. Microsoft's docs go out of date rather quickly. https://github.com/sendgrid/sendgrid-csharp
I am analyzing a users Exchange mailbox with calls to the ExchangeService. This tool needs to run on the client environment periodically and by ommiting the credentials to the service I am connecting to the Exchange Service as the logged in Windows User. I can succesfully loop thrue the folders and items.
Now I want tot retrieve the information about the mailbox being used. Username and (main) E-mail should suffice. But I cannot find anything about how to retrieve this information. Every example provides credentails for the user, or auto-discovering the Exchange service from the e-mail adres. I do not want the user to configure anything :-).
Any suggestions?
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Url = new Uri("https://FQDN/EWS/Exchange.asmx");
???
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.SentItems, new ItemView(100)); // this works
I've tried using service.ResolveName, but that can give multiple answers, even using Environment.UserName
The easiest method to do this is to use ConvertId operation and use unresolvable address (blah#blah.com always works for me) in the Mailbox element. Exchange should convert this to the actual Mailbox in the response. eg
Folder chk = Folder.Bind(service, WellKnownFolderName.Inbox);
AlternateId aiItem = new AlternateId();
aiItem.Mailbox = "Blah#Blah.com";
aiItem.UniqueId = chk.Id.UniqueId;
aiItem.Format = IdFormat.EwsId;
String CasServer = service.Url.Host.ToString();
AlternateIdBase caid = service.ConvertId(aiItem, IdFormat.HexEntryId);
Console.WriteLine(((AlternateId)caid).Mailbox);
Cheers
Glen
I am writing a windows service that will be doing a lot of network communication (copy many many files in shared folders and modify database).
I need a way to notify a user (if logged on) of any exceptions/errors. My issue is do group to errors for send it (by email) to administrator address.
I am aware of event logging neither notification bubble from system tray, but the administrator not views that log, he prefers email.
The ideal component is ASP.NET Health Monitoring, but only works for IIS, and it is required a component similar for Windows Services.
Any sample application Windows Service in C# or another language in .net (with source code) about this issue ??
If you're just needing a way to send an email notification, .Net has SMTP and mail types to take care of this. Email notifications are common in software anymore and that's why the commonly used functionality has been incorporated into the base class lib.
You could use SmtpClient, MailAddress, and MailMessage objects to accomplish what you need to simply send an email notification. Of course you need to have access to an SMTP server to transmit the mail, so find out what its host address is to properly configure your application. Here are a few examples:
SmtpClient mailClient = new SmtpClient("smtp.fu.bar");
MailAddress senderAddr = new MailAddress("you#fu.bar");
MailAddress recipAddr = new MailAddress("admin#fu.bar");
MailMessage emailMsg = new MailMessage( senderAddr, recipAddr );
emailMsg.Subject = "Test email.";
emailMsg.Body = "Here is my email string which serves as the body.\n\nSincerely,\nMe";
mailClient.Send( emailMsg );
That example is just straight code, but it would be better to put it into a reusable method like this:
public void SendNotification( string smtpHost, string recipientAddress, string senderAddress, string message, string subject )
{
SmtpClient mailClient = new SmtpClient(smtpHost);
MailMessage emailMsg = new MailMessage( new MailAddress(senderAddress), new MailAddress(recipientAddress) );
emailMsg.Subject = subject;
emailMsg.Body = message;
mailClient.Send( emailMsg );
}
check this : http://www.codeproject.com/Articles/16335/Simple-Windows-Service-which-sends-auto-Email-aler
my advice if it's first time to work with windows service (because Windows Service is very hard to debug)
first make it Command Line application with c#
when you be certain with all functionality of your project move it to Windows Service