Office 365 - MailKit hitting spam folders c# - c#

I am trying to use MailKit for sending email via office 365 for a web app that I am currently developing.
I have had various issues in the past with office 365 and sending emails and this evening I have stumbled across multiple articles and stack questions addressing office 365 and sending via smtp and MailKit being the preferred option.
I am using this code
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Simon Price", "simon.price#xxxx.co.uk"));
message.To.Add(new MailboxAddress("Recipient Nasme", "emailAddress"));
message.Subject = "Still hitting spam";
message.Body = new TextPart("html")
{
Text = #"sample test"
};
using (var client = new SmtpClient())
{
client.Connect("smtp.office365.com", 587, SecureSocketOptions.Auto);
// Note: only needed if the SMTP server requires authentication
client.Authenticate("simon.price#sxxx.co.uk", "xxxx");
client.Send(message);
client.Disconnect(true);
}
Which does send the email, however, it continually hits the spam folders of each recipient. I very much suspect this is me missing a configuration, however I cannot see where I am going wrong in this and would appreciate some help.
Resources I have looked at include but not exhausted (i may have missed some)
https://github.com/jstedfast/MailKit
https://dotnetcoretutorials.com/2017/11/02/using-mailkit-send-receive-email-asp-net-core/
Does Office 365 have a preferred way of sending attachments when using MailKit?
Authenticating to Office 365 Outlook IMAP using MailKit fails for a specific user
https://unop.uk/sending-email-in-.net-core-with-office-365-and-mailkit/

Related

SMTP mail with encrypt permission Outlook

When I send a mail with the option "Encrypt only" in Outlook
I receive a mail like this :
Currently, I use SMTPClient with MailMessage to send mail :
MailMessage message = new MailMessage();
message.From = from;
MailAddress to = new MailAddress(destString);
message.To.Add(to);
message.Subject = subject;
smtpClient.Send(message);
How can I modify my code to send a mail and receive it as the mail above ?
After some researching, I found a solution by using Interop but I can't use it in my project.
var app = new Microsoft.Office.Interop.Outlook.Application();
var item = (Microsoft.Office.Interop.Outlook.MailItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
item.To = abc#gmail.com;
item.Subject = "test";
item.Permission = Microsoft.Office.Interop.Outlook.OlPermission.olDoNotForward;
item.PermissionService = Microsoft.Office.Interop.Outlook.OlPermissionService.olWindows;
item.Send();
As far as I understand Outlook puts the message in a secure server (Office 365 in my case) and sends the recipient a link to open that message.
It is stated in this url, this feature is only for some licenses.
Microsoft 365 Message Encryption is part of the Office 365 Enterprise E3 license. Additionally, the Encrypt-Only feature (the option under the Encrypt button) is only enabled for subscribers (Microsoft 365 Apps for enterprise users) that also use Exchange Online.
I cannot find an API or library documentation, but you should try to communicate with your MS representative about this, so they can provide more information.

Email not sending in azure web app

I have configured my application in Azure web apps. I am sending the mail using smtp server. The outlook is sending emails properly. Other mail providers like(Gmail) are not sending emails. Please help.
Other mail providers like(Gmail) are not sending emails
You could check the providers that have policy to allow to do that.
Take gmail for example, as Ankit Kumar mentioned that you need to turn Allow less secure apps: on for your gmail account.
I also test it on my side, it works correctly. The following is my demo code.
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Tom Gmail", "xx#gmail.com"));
message.To.Add(new MailboxAddress("Tom Hotmail", "xxx#hotmail.com"));
message.Subject = "I am a mail subject";
message.Body = new TextPart("plain")
{
Text = "I am a mail body."
};
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
client.Authenticate("sunguiguan#gmail.com", "#WSX3edc");
client.Send(message);
client.Disconnect(true);
}
We also could use SendGrid on the Azure,more detail please refer to How to Send Email Using SendGrid with Azure.

Sending mail from office365 account C# mail headers

I can send mail with a valid Office365 account using my C# web application to a list of opt-in addresses. So it is our own data source with our customers in it. The problem is that it is probably not received by our customers. I have send a mail from the info account to my own office365 account and pasted the headers in mxtoolbox and got a message that my local pc is blacklisted. even when it is using the smtp of office365. We have dkim enabled and spf in the dns. What else should I do to troubleshoot this?
Here is my simple C# code for sending the mail (which works, but might needs additional anti-spam stuff?)
SmtpClient sc = new SmtpClient();
sc.Host = "smtp.office365.com";
sc.Credentials = new System.Net.NetworkCredential(SmtpUsername, SmtpPassword);
sc.Port = 587;
sc.EnableSsl = true;
Should I add my home IP and from the office to the SPF dns entry, even when I am using the smtp of office365?
this is the value for Authentication-Results
dkim=none (message not signed) header.d=none;ouroffice365domain.com; dmarc=none action=none
Is that the cause for getting on the blacklist? Please note that I am not trying to send spam. It is a valid data source where people opted in for. We are just migrated to office365 and need to send a mailing to our customers from our custom web application. We are aware of the limitations (10k per day) and 1 mail every 2 sec.
edit will change this: https://stackoverflow.com/a/23409351/169714 because I just used the mail address and not the first and last name of the customer.
Not having DKIM setup is not going to get you blackisted, having it set up improperly can. Your HOME PC should have nothing to do with SPF, it's the lasting sending IP which should be OFFICE 365 IP. Did you validate your DKIM and SPF by sending an email to mailtest#unlocktheinbox.com or check-auth#verifier.port25.com?
I also don't think your LOCAL PC is blacklisted, it's the IP of your INTERNET Provider that is blacklisted. Unless you have a static IP it will change.

Sending email through MS Outlook and disabling the warning

I have a C# program that I will be running on a daily basis (through Windows Scheduler). The program is to send a daily report to my team.
I have written the following to send the email and it works. the only problem is that Outlook shows a message box " A program is trying to send an e-mail message on your behalf. if this is unexpected...... " . there are three buttons "allow" "deny" "help" and it seems like my program is halted at that point and until i click the allow or deny button , the program doesn't send the email.
I know that the i can change the options by going into tools -> trust center -> programmatic access, but i would really like to not use that because this program would be eventually running from another machine where the user may or may not access to change the setting in trust center.
Is there a way to disable this warning programatically? ..or is there another way to send the email without having this warning popup
here is the code used to send the email..and it works fine..
Application olook = new Application();
NameSpace ns = olook.GetNamespace("MAPI");
ns.Logon(null, null, true, true);
_MailItem msg = (_MailItem)olook.CreateItem(OlItemType.olMailItem);
msg.To = "xxx#xxx.com";
msg.Subject = "test";
msg.HTMLBody = strHTML;
msg.Send();
ns.Logoff();
there are several ways to do that
you could disable the popup like #DJ KRAZE described
or you could send a message via smtp, if thats possible in your environment
see this: http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
then you could use the "redemption library" i've used it and there will be no messages, because redemption suppresses them (or works around them) but the library is used via com, thats not that comfortable..
although you have to pay for that:
http://www.dimastr.com/redemption/home.htm
the thir alternative is using the managed Exchange Web Services
http://www.microsoft.com/download/en/details.aspx?id=13480
this is pretty straight forward and fun to use. you can get that via NuGet as well. :)
EDIT:
i forgot to mention, that Exchange Web Services are only available on Exchange 2007 SP1 or higher.
and this is what it looks like to send a message (after connect to the server)
EmailMessage message = new EmailMessage(service);
message.Subject = "Hello from the EWS Managed API";
message.Body = "Now that's easy!";
message.ToRecipients.Add("someone#fabrikam.com");
message.Save();
look here for an introduction: http://msdn.microsoft.com/en-us/library/dd637749(v=exchg.80).aspx
One of the easiest solutions is to use Exchange's SMTP server. Here's an example from MSDN.
string to = "jane#contoso.com";
string from = "ben#contoso.com";
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = #"Using this new feature, you can send an e-mail message from an application very easily.";
SmtpClient client = new SmtpClient(server);
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.UseDefaultCredentials = true;
client.Send(message);
Of course, you'll have to check with your Exchange administrator to make sure that SMTP is enabled.

What to use in 'SmtpMail.SmtpServer = "???", in Microsoft Exchange Server

I am trying to write code to send a simple mail from asp.net page.
Confusion is over what to write under "smtp server", when I want to send mail using Microsoft Outlook 2007.
Two sets of code I'm trying:-
1.)
MailMessage objMail = new MailMessage();
objMail.From = "angenlina.jolie#compnayabc.com";
objMail.To = "brad.pitt#companyabc.com";
objMail.BodyFormat = MailFormat.Text;
objMail.Priority = MailPriority.High;
objMail.Subject = "Hi Sweetheart";
string smtpadd = "USA-LA-MAIL1.corp.hollwood.com";
SmtpMail.SmtpServer = "smtpadd";
SmtpMail.Send(objMail);
2.)
SmtpClient smtp = new SmtpClient();
smtp.Port = 25;
smtp.Host = "USA-LA-MAIL1.corp.hollwood.com";
smtp.Credentials = new NetworkCredential("username", "password");
MailMessage email_msg = new MailMessage();
email_msg.To.Add("brad.pitt#companyabc.com");
email_msg.From = new MailAddress("angenlina.jolie#companyabc.com");
email_msg.Subject = "test mail...";
email_msg.Body = "Hi SweetHeart";
email_msg.IsBodyHtml = false;
smtp.Send(email_msg);
Now my problem is what server name should I use for Microsoft outlook 2007(MS exchange server)?
Now my problem is what server name should I use for Micrsoft outlook 2007(MS exchange server)?
Are you sending email via MAPI (using their "Outlook profile") or via SMTP through an Exchange Server? They're not the same.
If you are sending through Exchange then the server will need to be configured to relay mail via SMTP. In which case, put the Exchange server in as the SMTP server.
If you're sending email via MAPI then you'll be using whatever mail server is configured in their "Outlook profile". Which could be SMTP, IMAP, Webmail (with a Hotmail connector or Gmail connector) or Exchange Server.
EDIT:
It sounds like you want to use the Exchange server via MAPI. Here is a good primer to the technologies involved.
Bear in mind that if you're configuring MAPI profiles from within the ASP .NET application you're going to pay attention to the service account the ASP .NET application runs as and that the MAPI is sometimes interactive and not suitable for service based applications.
You may be better off having an administrator configure the Exchange server to route email via SMTP (which is most likely is, unless you have a spam appliance in front of the server which handles SMTP).
try something generic i.e
Email Client setup information
IMAP server: imap.smtpserver.in
POP server: pop.smtpserver.in
SMTP server: smtp.smtpserver.in
Webmail
To access your email through a web browser visit http://webmail.smtpserver.in
smtpserver.in is your smtpserver host address.

Categories

Resources