Unable to send mail from C# App using godaddy details - c#

Despite spending an entire morning with GoDaddy chat, and reading almost everything I can find on sending emails via godaddy I am still no closer to solving my issue.
What Have I tried
Firstly, this is my code.
var smtpClient = new SmtpClient("smtpout.secureserver.net")
// var smtpClient = new SmtpClient("relay-hosting.secureserver.net", 25)
{
Port = 25,
UseDefaultCredentials = false,
EnableSsl = false,
Credentials = new NetworkCredential("user#User.com", "Password#"),
// DeliveryMethod = SmtpDeliveryMethod.Network,
};
and I think I should mention that this works when I attempt to use google's free smpt server, the mail is sent. However using my godaddy credentials, I get the following error,
Message = "Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 72.167.234.197 (72.167.234.197:25), connect error 10060" other times it says
InnerException = {"Unable to read data from the transport connection: An established connection was aborted by the software in your host machine."}
I have also tried other suggested ports like 587 , 80, 3552. Nothing has changed, I have also tried the suggestion at this link https://www.godaddy.com/help/send-email-using-systemnetmail-19291 . Which did not work (no suprise to me, cause where am i putting the account password) . Would appreciate it if anyone has solved getting their C# application to work with Godaddy. Like I said it works with Google so I dont believe my code is an issue in anyway.
regards

Your code looks good, however, one way to test if you are using the correct smtp settings is to send the email with a program like Microsoft Outlook or Thunderbird. Also, if you are using a dedicated server or a VPS, you need to use
dedrelay.secureserver.net
See: https://in.godaddy.com/help/what-is-my-servers-email-relay-server-16601
Also, check out this see: https://in.godaddy.com/community/VPS-Dedicated-Servers/Unable-to-send-email-from-C-net-application-from-website/m-p/102913#M1256
which mentions: "If you are using a Plesk shared hosting plan, use relay-hosting.secureserver.net and port 25. Do not specify a username or password. Other relay/smtp servers will not work from our shared hosting."

Related

Send email from C# WPF app without external SMTP

I need to find a way to send e-mails from my WPF application. Of course I tried sending it using for example Gmail SMTP and it works like a charm but for some reason this solution is unacceptable. So is there a way to send email straight from my computer without using any logging credentials or additional/not open source software? I tried something like this:
SmtpClient m = new SmtpClient();
m.Host = "xxx.xxx.xxx.xxx"; // my IP address.
m.Port = 25;
m.Send("Tests#xxx.xxx.xxx.xxx", "tests#gmail.com", "Test", "This is a test email.....");
It doesn't work like that, I've put mu IPV4 addres from ipconfig but the error I got is:
No connection could be made because the target machine actively refused it.
Is this even possible to run this straightforward from my PC like that? I assume its not even my static IP but some kind of dynamically changed IP from my ISP hidden behind NAT. How to configure it in other way?
My app is expected to run for example overnight and then I would like to receive and email after process is finished. Not interested in receiveing any other emails or sending emails to multiple users.
Sending email via SMTP is not complicated is just very legislated.
Each mail provider gmail/office365 has a configuration which you must follow exactly. The configuration is not even to send the email its just to autorize yourself for the smtp account being used.
Doing a quick search online for gmail the conditions are currently::
https://support.google.com/mail/answer/7126229?visit_id=1-636683482170517029-2536242402&hl=es&rd=1
Good luck

How to send an email from office365 account using domain windows authentication

I'm developing a console app which will be executed from a windows service that needs to send emails using the domain account associated to the domain account running the windows service.
In my development machine I'm logged with a domain account that belongs to the same domain that will run the windows service but I'm not able to get it working properly.
For this development I'm using .NET 4.6.1 and the nuget package FluentEmail.Smtp
My code looks like this:
Email.DefaultSender = new SmtpSender(new SmtpClient
{
UseDefaultCredentials = true,
EnableSsl = true,
Host = "smtp.office365.com",
TargetName = "STARTTLS/smtp.office365.com",
Port = 587,
DeliveryMethod = SmtpDeliveryMethod.Network
});
await Email.From("myname#mycompanydomain.com", "Some tittle")
.To(emailListObject)
.Subject("Some subject")
.Body("Some body", true)
.SendAsync();
With this code I'm getting the following exception:
Unable to connect to the remote server
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 52.96.9.178:587
at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result)
at System.Net.Mail.SmtpTransport.EndGetConnection(IAsyncResult result)
at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
Note: From my machine I'm able to ping the IP mentioned in the exception
I'll appreciate your assistance
For starters you might want to take a look at the official document - direct send. You will note that there are quite a few issues (such as TLS security) alongside proper configuration of your Exchange server.
Without more information in your question it is rather limited as to what can be answered, however as an alternate solution, maybe take a look at direct send. (which is much less effort).
Settings for direct send
Enter the following settings on the device or in the application directly.
Server/smart host. Use your MX endpoint, for example, contoso-com.mail.protection.outlook.com
Port. Use port 25
TLS/StartTLS. Enable this.
Email address. Use any email address for one of your Office 365 accepted domains. This email address does not need to have a mailbox.
Microsoft recommends adding an SPF record to avoid having messages flagged as spam. If you are sending from a static IP address, add it to your SPF record in your domain registrar's DNS settings as follows:
DNS entry Value
SPF v=spf1 ip4:<Static IP Address> include:spf.protection.outlook.com ~all

c#-Unable to retrieve email using openpop.net

I build an application to retreive email from gmail account. I can very well view email on my development PC, however when I run the setup on production PC(client PC), it gives error
POP3 Server Authentication-The server did not accept user credentials.
I tried replacing port from 995 to 587 and 465, but same issue.
I also added AuthenticationMethod.UsernameAndPassword
My code for connection:
if (pop3Client.Connected)
pop3Client.Disconnect();
pop3Client.Connect(popServerTextBox.Text, int.Parse(portTextBox.Text), useSslCheckBox.Checked);
//pop3Client.Authenticate(loginTextBox.Text, passwordTextBox.Text,AuthenticationMethod.UsernameAndPassword);
pop3Client.Authenticate(loginTextBox.Text, passwordTextBox.Text);
What am I missing here.
Thanks
I am able to solve the issue. It was gmail who was blocking connection, I just needed to add production PC on gmail and it worked.
Thanks

The remote name could not be resolved http://schemas.microsoft.com/cdo/configuration/smtpauthenticate

Full error
System.Exception: Error sending email (0 bytes): Mailbox unavailable.
The server response was: 5.7.1 Client does not have permissions to
send as this sender ---> System.Net.Mail.SmtpException: Mailbox
unavailable. The server response was: 5.7.1 Client does not have
permissions to send as this sender
I inherited a project five years ago, and it is at least six years old. The project contains a couple of web applications and a few desktop apps & services.
The web application sends email pretty regularly, and it has been running without much in the way of problems until recently.
When we started getting this error, I tried a few things on my end. I created a small test web app and deployed it on a separate server. I used the same mail server, address, and credentials. It works fine. I also used dbmail on the same server the problem app is located, again using the same mail address. It works also.
I've read maybe six or seven questions & answers on the subject here and elsewhere, to no avail. It seems pretty clear that this is the mail server returning this error. But why would SQL Server's dbmail and the test app I made send if that were the case?
Here is the connection information with a few changes for the sake of anonymity.
static void SendEmail(MailMessage msg)
{
msg.Headers["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = "2";
using (var c = new SmtpClient
{
Host = "mailserver.address.com",
Port = 587,
UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential("UserName", "password", "address.com"),
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network
})
{
try
{
c.Send(msg);
}
catch (Exception ex)
{
var size = msg.Attachments.Sum(a => a.ContentStream.Length);
throw new Exception(string.Format("Error sending email ({0} bytes): {1}", size, ex.Message), ex);
}
}
}
What has greatly exacerbated the problem is that the source code I have for roughly half of these apps is clearly not the identical of the code deployed. They had zero version control when I first started years ago. So, I can't easily tweak around in the code and redeploy because it will break the entire application. I would have to do a full-blown overhaul (and actually, I am, but it's not going to be ready anytime in the immediate future).
Any advice is greatly appreciated.
I've found the cause.
The port wasn't added in my test. When added, it causes the error.
Why would this break on a certain date this month?
This is a mail server issue. A sysadmin is the only person that can fix this, and I was able to get them to resolve. Thanks.

5.7.0 Must issue a STARTTLS command first

I'm trying to send email through C#. Although I beleive I've done everything right, it still throws this exception :
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"
At first I thought, it could be a zone/ip/region problem... But when i logged into gmail, there wasn't any warning of that. And to be sure, i've uploaded a file to a website to check from there, still the error was thrown.
Than I've tried changing the port to 465. It didn't work either.
I've first tried with accounts that are managed by a Google Apps account. So I thought it could be it, but it wasn't either...
I'm truly out of ideas right now.
Any of you have an idea ?
Here is the example code :
SmtpClient sm = new SmtpClient("smtp.gmail.com",587);
sm.Credentials = new NetworkCredential("blabla#gmail.com","**");
sm.UseDefaultCredentials = false;
sm.EnableSsl = true;
sm.DeliveryMethod = SmtpDeliveryMethod.Network;
sm.Send("blabla#gmail.com","blabla2#tr3reklam.com","Test","Test");
** Note **
I've checked the account name and password, they both are right.
"Access for less secure apps" must be enabled for the Gmail account used by the NetworkCredential using Google's settings page.
It was caused by 2-Step Verification after all !
It is odd, but without turning on "Allow users to be able to turn on 2-Step verification on" option set to true, I couldn't send any mails.
2-Step verification is still off for the accounts but, probably allowing users to choose for themselves make some security settings in the background.
I couldn't find any documentation about this but I can send now...
Put the code sm.UseDefaultCredentials = false; before sm.Credentials = ...

Categories