Error: Server does not support secure connections - asp.net

Ok, I have been using the following script for over a year now to send email (via gmail) from my host, and it has worked just fine (the Settings.Get() just return strings):
public class Email : SmtpClient
{
public MailMessage Message { get; private set; }
public Email(string to, string from, string subject, string body) : base(Settings.Get("smtp"), 25)
{
this.EnableSsl = Convert.ToBoolean(Settings.Get("ssl"));
if(this.EnableSsl)
this.Credentials = new System.Net.NetworkCredential(Settings.Get("gm"), Settings.Get("gmp"));
this.Message = new MailMessage(from, to, subject, body);
}
public void Send()
{
try { this.Send(Message); }
catch (Exception ex) { throw ex; }
}
}
But, since yesterday, I have been getting this error:
Error: Server does not support secure connections.
Now of course my host thinks it's not their fault, BUT I DIDN'T CHANGE ANYTHING. Also, it still works fine on my local and test machines. Any idea what might be causing this so I can tell them to fix it?
Thank you... this is driving me nuts!

What SMTP-Server and port are you using? You will need to use port 465 or 587 if you are connecting directly to smtp.gmail.com to send ssl mail.
It looks like you are using port 25, are you sure that your Settings.Get("ssl") returns false?
Read here for details.

Change:
SmtpServer.EnableSsl = true;
To:
SmtpServer.EnableSsl = false;
This will sort the issue.

check your event log, maybe the handshake beetwen the your pc and the server is not working.or the certificate is not being downloaded or it may contain errors wich may be something weird comming from gmail

Specifying the port to use 587 has also solved that problem for me -
Error: Server does not support secure connections.
The company I for work created a windows service that does some stuff and then sends an email from gmail. In the beginning it sent the email just fine with no problems. After installing the service on a Vista machine we noticed it would not send the email. Then the same thing once we installed it on windows 2008 server. We've even start to notice it a small number of XP machines. Once we changed the port to 587 it started to work fine again and send the emails.
Here is some sample code that has worked on all machines we have tried (XP, Vista, Server 2008).
Dim client As New Net.Mail.SmtpClient("smtp.gmail.com")
client.Port = 587
client.EnableSsl = True
client.UseDefaultCredentials = False
client.Credentials = loginInfo
client.Send(mm)

SmtpServer.Port = 587;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("xx#xx.com", "password");
SmtpServer.EnableSsl = true;

Go to C:\Program Files\Microsoft SQL Server Reporting
Services\SSRS\ReportServer\rsreportserver.config and locate 'True' and set it to false as below:
'False'
Restart the SSRS services and you should be good.

Related

Sent an email from asp.net through 365 with a "from" email that is different than the username

I hope someone can help me out here:
Users generate emails through my asp.net website. Emails are to be sent out through the 365 server using an account that I have there with my domain (e.g. out#mydomain.com). I want the message "from" field to be the email of my user (e.g., myuser#anotherdomain.com) so that the receivers of the email will see his email as the sender and will reply to him directly.
But when I try this I get an error message (see below).
I get the same error message even if I try to send an email when the "from" field is another existing mailbox in my domain (e.g., myname#mydomain.com)
Apparently someone in the way (not sure if the asp.net or the 365 server) blocks emails if the "from" is not identical to the username.
Is there any way to address this>
here is my code
protected void btnSend_Click(object sender, System.EventArgs e)
{
AuditLog.Info("here");
try
{
string EmailContent = "test";
MailMessage msg = new MailMessage();
msg.IsBodyHtml = true;
msg.From = new MailAddress("myuser#anotherdomain.com");
msg.Bcc.Add(msg.From);
string email = "receiver#gmail.com";
msg.To.Add(email);
msg.Subject = "TEst 365";
System.Net.Mail.AlternateView plainTextView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(EmailContent);
System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(EmailContent);
msg.AlternateViews.Add(plainTextView);
msg.AlternateViews.Add(htmlView);
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.office365.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = "out#mydomain.com", "MyPassword");
client.Port = 587;
client.EnableSsl = true;
if (client.Host.Trim() != "")
client.Send(msg);
}
catch (Exception ex)
{
AuditLog.Info(string.Format("Failed to send mail . Error={0} ", ex.Message));
}
finally
{
AuditLog.Info("end");
}
}
And this is the error:
{"Transaction failed. The server response was: 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 0.35250:0A00A280, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:FD1E0000, 1.36674:0E000000, 1.61250:00000000, 1.45378:021F0000, 1.44866:14030000, 16.55847:AD0F0000, 17.43559:0000000004020000000000000000000000000000, 20.52176:140F2A8A0A00101043050000, 20.50032:140F2A8A7A17000000000000, 0.35180:48050000, 255.23226:0A00A780, 255.27962:0A000000, 255.27962:0E000000, 255.31418:0A00A880, 0.35250:0A000000, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:20000000, 1.36674:32000000, 1.61250:00000000, 1.45378:25000000, 1.44866:01000000, 16.55847:8C000000, 17.43559:0000000030030000000000007B00000000000000, 20.52176:140F2A8A0A0070200A00AD80, 20.50032:140F2A8A7A1710106B050000, 0.35180:0A00AE80, 255.23226:4800D13D, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:75050000, 4.21921:DC040000, 255.27962..."}
It's right there in the error message: Exception:SendAsDeniedException.MapiExceptionSendAsDenied;
You will need to grant your users SendAs permissions for out#mydomain.com. That's probably not what you really want to do though, as those users would then consume an office 365 license and if they were using a license, they could just send as themselves.
The real solution is to not use office 365 as an SMTP relay. You should sign up with another SMTP provider that is specifically set up to do what you are trying to do. We use SendGrid, but there are others out there if you search.

149.xxx.xxx.xxx is my address exception (C#, ASP.NET CORE 2.0, SMTP-client, MailKit)

Good day, dear collegues!
I'm trying to send email using SMTP-server, created by my collegue. I'm using .net core 2.0 this Identity.
When I run my application at debug-mode using my own computer -- it works perfectly.
When I run the same app on hosting it throws this exception:
SmtpCommandException: 149.xxx.xxx.xxx is my address
MailKit.Net.Smtp.SmtpClient.OnSenderNotAccepted(MimeMessage message, MailboxAddress mailbox, SmtpResponse response)
the hosting and the smtp-server have the same IP-address and work at the same computer.
I'm sure, that exception of form "149.xxx.xxx.xxx is my address" means, that smtp-server thinks, I'm spamer, trying to use its IP to be "whitelisted" -- and this server blocks me.
I've found this:
HELO is faked interface address
Type: forgery
Some spammers put the server's interface address they connect to in their HELO, maybe asuming it is whitelisted or something.
drop condition = ${if eq{[$interface_address]}{$sender_helo_name}}
message = $interface_address is my address
But the same hosting has many other web-applications, they don't have a problem with connection to the local server.
public async Task SendEmailAsync(string email, string subject, string message)
{
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress("No reply", "XX#XXXX.XXX"));
emailMessage.To.Add(new MailboxAddress("", email));
emailMessage.Subject = subject;
emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html)
{
Text = message
};
using (var client = new SmtpClient())
{
await client.ConnectAsync("localhost", 25, SecureSocketOptions.None);
await client.AuthenticateAsync("XX#XXXX.XXX", "Password");
await client.SendAsync(emailMessage);
await client.DisconnectAsync(true);
}
}
I tried to use its address instead of "localhost". But it throws the same exception.
What should I do? How to say a smtp-server that I'm not spamer, that I'm just physically situated on its IP-address, on the same computer?
Yes, now I've done it!
I needed to use direct connection to local mail server (without SMTP, this is very important).
How to implement direct connection? My web-server uses Linux Ubuntu system. So I needed to use the Shell (Ubuntu terminal).
Firstly I've tested it manually: when I type "sendmail" (command for direct usage of local mail server) it requires email of recipient.
And I needed to type in terminal:
$ sendmail xxx#mail.com
subject:My subject //this is new line
to:xxx#mail.com // this is new line
from:kkk#mydomain.com // this is new line
Here I can write many lines of my letter's body.
. // this is the point in new line (the only symbol) to show this is end of the letter. Next keyboard "enter" means to send finally.
To use these commands, I needed to create new process (the same as to give command "sendmail").
So, instead of this all:
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress("No reply", "XX#XXXX.XXX"));
emailMessage.To.Add(new MailboxAddress("", email));
emailMessage.Subject = subject;
emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html)
{
Text = message
};
using (var client = new SmtpClient())
{
await client.ConnectAsync("localhost", 25, SecureSocketOptions.None);
await client.AuthenticateAsync("XX#XXXX.XXX", "Password");
await client.SendAsync(emailMessage);
await client.DisconnectAsync(true);
}
I've just inserted
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "sendmail";
info.Arguments = $"{email}";
info.RedirectStandardInput = true;
info.UseShellExecute = false;
info.CreateNoWindow = true;
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
sw.WriteLine("from:kkk#mydomain.com");
sw.WriteLine($"to:{email}");
sw.WriteLine($"subject:{subject}");
sw.WriteLine(message);
sw.WriteLine(".");
}
}
p.WaitForExit();

Notify user when wcf service is stopped in windows phone 7

I have a windows phone 7 app which uses a wcf service in some events. I need to notify the app user when the service is temporary not available. ie. the user should be prompted with appropriate msg to try after sometime or so and the app should work with the cashed data. I tried to use the code:
public static Boolean isSiteOnline(String url)
{
Boolean result = true;
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(url);
httpReq.AllowAutoRedirect = false;
HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse();
if (httpRes.StatusCode != HttpStatusCode.OK)
result = false;
httpRes.Close();
return result;
}
But in Windows phone 7 am not able to get the function GetResponse()[Ln 6]. Is there any namespace that am missing? or is there any other way out?
Windows Phone does not support many synchroneous functions. GetResponse is one of them.
You sould use asynchronous version - BeginGetResponse
Sample can be found here - http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(VS.95).aspx

System.Net.Mail.SmtpFailedRecipientException: Mailbox name not allowed

I have written ASP.Net code to send mails from domain1.com mail account such as abc#domain1.com. This code work fine otherwise and the mails go. But when the same code executes on domain2.com, even with correct userid-pwd it gives the following error:
System.Net.Mail.SmtpFailedRecipientException: Mailbox name not allowed. The server response was: sorry, that domain isn't in my list of allowed rcpthosts (#5.7.1) at System.Net.Mail.SmtpClient.Send(MailMessage message)
Is there any way to fix this?
If we have to add this domain in the list of allowed rcphosts, how can that be done?
The code written is something like this:
MailMessage message;
bool success;
message = new MailMessage(from, to);
Attachment file;
SmtpClient lclient;
lclient = new SmtpClient("mail.domain1.com", 587);
lclient.EnableSsl = false;
message.Body = body;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
message.Subject = subject;
message.SubjectEncoding = System.Text.Encoding.UTF8;
lclient.SendCompleted += new
SendCompletedEventHandler(SendCompletedCallback);
lclient.UseDefaultCredentials = false;
lclient.Credentials = new NetworkCredential(userID, password);
try
{
lclient.Send(message);
success = true;
if (message != null)
message.Dispose();
success = true;
return (success);
}
catch (Exception ex)
{
//...
}
Thanks
The code works fine. The error is a rejection from the SMTP server. It would seem that the server, when accessed from Domain1, allows you to forward mail through it. When accessed from Domain2, it does not. Changing this would be a configuration on the SMTP server.
Note that this is common practice for SMTP services. They generally don't allow anybody to send mail through them to any address. (That would leave them wide open for spammers and other such unwanted activities.) So, if you're trying to access Domain1's SMTP service from outside of Domain1, it's probably just rejecting that.

A local error has occurred while connecting to AD in Windows 2008 server

There's Active directory on windows 2000 advance server, I have a web server on Windows 2008 server Enterprise Edition, the following code works fine in Winsows 2003 server but when I installed Win 2008 server, it gives me the following error, the webserver is not subdomain of the AD server. but they have the same range IP address.
A local error has occurred.
System.DirectoryServices.DirectoryServicesCOMException
I want to Authenticate Via AD from my webserver, I even test the port 389 and it was open(by telnet), I even added port 389 UDP and TCP to firewall of webserver to be sure it is open, even I turned the firewall off but nothing changed. I don't know what's wrong with Windows 2008 server that cannot run my code, I search Internet but I found nothing.
any solution would be helpful.
Thank you
public bool IsAuthenticated(string username, string pwd,string group)
{
string domainAndUsername = "LDAP://192.xx.xx.xx:389/DC=test,DC=oc,DC=com" ;
string usr="CN=" + username + ",CN=" + group;
DirectoryEntry entry = new DirectoryEntry(domainAndUsername, usr, pwd,
AuthenticationTypes.Secure );
try
{
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
SearchResult result = search.FindOne();
if (result == null)
{
return false;
}
}
catch (Exception ex)
{
return false;
}
return true;
}
Ok, let's try a different approach... You indicated that you're on Windows 2008 which means that you should be able to use the new System.DirectoryServices.AccountManagement-namespace introduced in .NET 3.5.
I've written a quick function that you can try out which should work better than the code you're currently using:
using System.DirectoryServices.AccountManagement;
//...
private Boolean IsAuthenticated(String username, String password, String group)
{
PrincipalContext domain;
try
{
// Connect to the domain:
domain = new PrincipalContext(ContextType.Domain, "192.xx.xx.xx", username, password);
}
catch
{
// Unable to connect to the domain (connection error or bad username/password):
return false;
}
PrincipalSearcher searcher = new PrincipalSearcher();
// Search for the user in the domain:
UserPrincipal findUser = new UserPrincipal(domain);
findUser.SamAccountName = username;
searcher.QueryFilter = findUser;
UserPrincipal foundUser = (UserPrincipal)searcher.FindOne();
// Search for the group in the domain:
GroupPrincipal findGroup = new GroupPrincipal(domain);
findGroup.SamAccountName = group;
searcher.QueryFilter = findGroup;
GroupPrincipal foundGroup = (GroupPrincipal)searcher.FindOne();
if (foundGroup != null)
{
// Return true if group exists and the user is a member:
return foundUser.IsMemberOf(foundGroup);
}
else
{
// Group was not found:
return false;
}
}
However I would recommend that you set up a service account in your domain and use that account (with a password that you know) in your application instead of connecting to the directory with the username/password of the user that you're autenticating.
The DirectorySearcher class is most likely the culprit.
Per MSDN on DirectorySearcher:
"Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements. "
The error you're getting indicates that you're able to access Active Directory (not a firewall issue) but AD is unable to process the request.
I'm not sure why the code worked on Server 2003 because these two lines...
string usr="CN=" + username + ",CN=" + group;
DirectoryEntry entry = new DirectoryEntry(domainAndUsername, usr, pwd, AuthenticationTypes.Secure );
...should never work because you're not supplying the username in the correct way (you can't simply add the username to a group name, it's not a valid DN). If you change it to...
DirectoryEntry entry = new DirectoryEntry(domainAndUsername, username, pwd, AuthenticationTypes.Secure );
...you should be able to make a successful connection to AD. There won't be any check if the user belongs to the supplied group however.

Resources