Cannot send email from SendGrid Account api key - c#

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.

Related

Sending a chat message with Microsoft Teams

Is there anyway to send a teams message to a channel or chat that doesn't involve the end user of an app being asked to sign in? What I am trying to do is something like this:
User does something on my web app
Without user interaction, my web app sends a message to a chat or channel on Microsoft Teams
I tried to send it as myself for testing (planned on using a service account later), but after some reading, I've come to find out isn't possible using application API permissions, as documented here:
Here is the code I have that would work if I wasn't using application permissions:
var tenantId = "...";
var clientId = "...";
var clientSecret = "...";
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var graphClient = new GraphServiceClient(clientSecretCredential);
var chatMessage = new ChatMessage
{
Body = new ItemBody
{
Content = "Hello World"
}
};
await graphClient.Teams["..."].Channels["..."].Messages.Request().AddAsync(chatMessage);
It throws this exception:
Microsoft.Graph.ServiceException: 'Code: Unauthorized
Message: Message POST is allowed in application-only context only for import purposes. Refer to https://docs.microsoft.com/microsoftteams/platform/graph-api/import-messages/import-external-messages-to-teams for more details.
Inner error:
AdditionalData:
date: 2023-02-16T04:46:02
request-id: 3cbd9dc8-a86a-43e9-a5fe-e9e9b3433566
client-request-id: 3cbd9dc8-a86a-43e9-a5fe-e9e9b3433566
ClientRequestId: 3cbd9dc8-a86a-43e9-a5fe-e9e9b3433566
Is it possible to send a message to a teams chat/channel without user interaction?
As per the documentation, application permissions are supported only for migration purposes. For this, your team and channel both must be created in a migrated state. However, you can use this graph API in a delegated context (with signed-in user).
Reference Document: https://learn.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-1.0&tabs=csharp
Using proactive messages you can send a message to a teams chat/channel without user interaction.
Reference Document: https://learn.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bot-conversations/bots-conv-proactive

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.

Change sender on reply using EWS Managed API

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

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.

Telegram API error USER_DEACTIVATED after authentication

I'm using a simple client for Telegram API on C# using TLSharp library.
var appId = ConfigurationManager.AppSettings["appId"];
var appSecret = ConfigurationManager.AppSettings["appSecret"];
var clientPhone = ConfigurationManager.AppSettings["clientPhone"];
...
var session = new FileSessionStore();
client = new TelegramClient(int.Parse(appId), appSecret, session, clientPhone);
await client.ConnectAsync();
if (!client.IsUserAuthorized())
{
hash = await client.SendCodeRequestAsync(clientPhone);
await client.MakeAuthAsync(clientPhone, hash, code);
}
var state = await client.SendRequestAsync<TLState>(new TLRequestGetState());
Here I'm getting exception USER_DEACTIVATED.
So, I tried to get new clean account (with new phone number), login throgth mobile telegram client, after that login to web version, searched some channels, subscribe, sent some messages. After that I tried to login with my client app and at FIRST request got same error.
This issue started to reproduce just this week. Before that I successfully used several test accounts, getting messaged, worked with media and dialogs, no any deactivate errors.
What I'm doing wrong? What limits or policies was broked my application and does exists any way to restore my app?
UPDATE
Tried to register new application from another account. After that, repeat same actions with new phone number and another PC with another IP address - banned after first request.
What is going on? Why can telegram blocks my accounts?

Categories