Change sender on reply using EWS Managed API - c#

I'm currently trying to configure Mail2Bug to create Bugs in Azure DevOps when new emails arrive in a shared mailbox. Everything was going well until the part where it needs to reply to the incoming message.
The code which handles this function can be found in EWSIncomingMessage.cs:
public void Reply(string replyHtml, bool replyAll)
{
//_message is of type EmailMessage
var reply = _message.CreateReply(replyAll);
reply.BodyPrefix = new MessageBody(BodyType.HTML, replyHtml);
reply.Send();
}
Instead of replying using the shared mailbox's email, it uses the one from the authenticated user. I'm assuming this has to do with how CreateReply populates the reply MailMessage in combination with EWS.
Are there any ways around this (possibly by creating a new MailMessage and simulate a reply)?

You could refer to the below code:
var message = (EmailMessage) Item.Bind(service, new ItemId(uniqueId), PropertySet.FirstClassProperties);
var reply = message.CreateReply(false);
reply.BodyPrefix = "Response text goes here";
var replyMessage = reply.Save(WellKnownFolderName.Drafts);
replyMessage.Attachments.AddFileAttachment("d:\\inbox\\test.pdf");
replyMessage.Update(ConflictResolutionMode.AlwaysOverwrite);
replyMessage.SendAndSaveCopy();
For more information, please refer to these links:
Replying with attachments to an email message with EWS
How to reply to an email using the EWS Managed API?
Respond to email messages by using EWS in Exchange

Related

Send email with SendGrid API using Office365 email account A which is set to send on behalf of an email account B

I am facing an issue with SendGrid API.
I have added a single user related to an Office365 email account, let's say a#tony.gr. This account has been configured to send on behalf of an other email account, let's say b#tony.gr.
I tried to implement a simple console application in C#, which sends an email message to a recipient from b#tony.gr.
var from = new EmailAddress("b#tony.gr", "B Account");
var subject = "Test";
var to = new EmailAddress("foo#foo.com", "Recipient");
var plainTextContent = "Hello world !!";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, null);
var response = await client.SendEmailAsync(msg);
When I execute the above code even if I do not get any error the mail is not sent.
However, when I set as "from" account the email account a#tony.gr the email is sent. I imagine that I have to include the added single user a#tony.gr in my code, but I don't know how.
Any help would be appreciated.
Thank you in advanced.
When you say you have "added a single user" I assume you mean you have verified that email address as a single sender.
SendGrid has no concept of Office365's configuration and the ability for a#tony.gr to be able to send a message on behalf of b#tony.gr. Your Office365 settings have no effect on how SendGrid works.
If you want to send emails from b#tony.gr then you will need to also verify that email address with SendGrid.

Cannot send email from SendGrid Account api key

i have created secret key from azure and use in code it's working perfectly fine but when i use secret key create from my gmail account i do not receive any email.
I am using the same code for both send grid api keys one from azure sendgrid account another from my direct sendgrid account but from azure sendgrid account emails are delivering without any error and in sendgrid activities tab also there is recent record but form my direct sendgrid account emails are not delivering and there is not recent record in activity tab.
static async Task Execute()
{
dynamic client = new SendGridClient("SG.Ge6udT3CQtKCuGIxhGwqkg.***************-B--zeJXJKnlomAzB2XzQ");
var msg = new SendGridMessage();
//noreply#teamx.ae
msg.SetFrom(new EmailAddress("360loyalofficial#gmail.com", "Teamx | Services"));
var recipients = new List<EmailAddress>
{
new EmailAddress("nauman.nasir138#gmail.com")
};
msg.AddTos(recipients);
msg.SetSubject("Test");
msg.AddContent(MimeType.Text, "test");
msg.AddContent(MimeType.Html, "test");
var response = await client.SendEmailAsync(msg);
}
Your messages won't be delivered because you don't own or control the gmail.com domain.
More details can be found here:
https://sendgrid.com/blog/dont-send-email-from-domains-you-dont-control/
but essentially it's a security feature to stop scammers and your message won't be delivered.

Send proactive message for Skype using Direct Line API

I am using Direct Line API v4 to send a message to my Web Chat proactively using an existing conversation (by passing the existing conversation ID, saved when the conversation started).
Code:
var client = new DirectLineClient("secreat");
var activity = new Activity();
activity.From = new ChannelAccount("userid");
activity.Type = "resume";
activity.ChannelId = "directline";
activity.Text = "Hi";
activity.Conversation = new ConversationAccount(id: "existingconverstaionid");
var result = client.Conversations.PostActivity("existingconverstaionid", activity);
This code runs fine and I am able to continue with my existing conversation with my Web Chat channel. I would like this same functionality to work for my Skype channel, so I have replaced userid and existingconversationid I received from the Skype conversation, but this does not work...
You can't use the DirectLineClient to broadcast a message to the Skype channel. It is actually quite easy, since you can just use the BotFramework SDK to send a proactive message, as long as you saved the conversation info.
Read more about sending proactive messages using BotFramework v4 or have a look at the example.

Full sms message has not been sent while sending sms through sendgrid c#

I want send sms through SMS gateway using send grid.
I am using following code for sending sms.
var sendgrid_message = new SendGridMessage();
sendgrid_message.AddTo(toNumber#domainname);
//set the sender
sendgrid_message.From = new MailAddress(from_address);
//set the message body
// sendgrid_message.Html = message;
sendgrid_message.Html = string.Format(" ");
//set the message subject
sendgrid_message.Subject ="The profile has been updated successfully. If you have not done this, please contact administrator.";
sendgrid_message.Text = "The profile has been updated successfully. If you have not done this, please contact administrator.";
//create an instance of the Web transport mechanism
var transportInstance = new Web(new NetworkCredential(username, password));
//send the mail
await transportInstance.DeliverAsync(sendgrid_message);
But I am not getting full content in SMS message.
I got message in following way
'The profile has been updated successfully. If you
'
Even if I use SMTP also, I am not getting full content.
Where am I wrong?
Do I need to follow another way to SMS?
Please let me know.

How to send email notification to newly created user in Active Directory using ASP.net C#

I have implemented a web application which manage all the operations(User Creation, User modification, User termination) on Active directory(#server.local).
I want to send a email from #server.local domain when an user creation has done, we need to notify the manager of the user.
Now the problem is, I am not sure about the SMTP configuration settings on that AD server and I have tried a method to send a mail. But It does not send the mail successfully. Its showing error message like Failure sending mail.
My Code is:
string SMTPHost = "10.26.60.350";
string fromAddress = "Admin.User#Server.local";
string toAddress = "Test.User#Server.local";
System.Net.Mail.MailMessage notMess = new System.Net.Mail.MailMessage();
notMess.To.Add(toAddress);
notMess.Subject = subject;
notMess.From = new System.Net.Mail.MailAddress(fromAddress);
notMess.Body = bodyParams;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(SMTPHost);
smtp.Send(notMess); // Here I am getting the exception
How to resolve this propblem? Do we need to configure any settings on AD server to send mail by using #server.local domain? Please help me on this and suggest me about this.Thanks

Categories