c#-Unable to retrieve email using openpop.net - c#

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

Related

Unable to send mail from C# App using godaddy details

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."

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

Can't login to Asterisk from .NET

I am trying to run the samples from Asterisk.NET . When I try to run the following piece of code from Asterisk.NET.Test:
manager = new ManagerConnection(ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD);
manager.Login();
I always get the follwing message:
AuthenticationFailedException: Authentication failed ... at ManagerConnection.cs:line 1263
Which username and password should I use?
I've tried "admin"/"admin"which I use for logging in at FreePBX web administration and with "admin"/"amp111", none of which work. I have not modified anything after installing AsteriskNow in VirtualBox. In the FreePBX web administration page every server status is green (ok).
Regards,
Tamas Ionut
Start Telnet on machine from which you are trying to connect and run commands:
telnet 000.000.000.000 5038
ACTION:LOGIN
USERNAME:username
SECRET:password
EVENTS:ON
Where 000.000.000.000, username, password are server address, username and password.
If you receive message "authentication failed" most likely the connection from your machine's address is not allowed for the user 'username'. The addresses from which the user is allowed to establish connection are configured on the server in config files.

Sending email through a Google Apps account is working locally, but not on my web server

Related:
Send Email via C# through Google Apps account
My question is the same so I implemented Koistya's solution as follows. The heartbreak is that it works beautifully on my dev laptop but when ported to web server it times out with no explanation.
My SMTP config is in my web.config file. I made mods based on Koistya's answer:
<mailSettings>
**Changed**
<smtp from="my#email.com">
<network host="smtp.gmail.com" password="[password]" port="587"
userName="my#email.com"/>
</smtp>
**Original**
<!--<smtp from="my#email.com">
<network host="mail.domain.com" password="[password]" port="25"
userName="my#email.com"/>
</smtp>-->
</mailSettings>
My .Net C# code (before & after removed):
SmtpClient mSmtpClient = new SmtpClient();
mSmtpClient.EnableSsl = true;
mSmtpClient.Send(message);
As I said this works great on my dev environment but not on web. Can anyone help? Thanks.
Your settings are correct. We use gmail for sending mail all the time in our web apps. Your server is probably blocking outgoing traffic on port 587. I would contact your host and see if they can help otherwise you will need new mail or a new host.
Thanks to everyone's help on this site as well as the Google apps forum (although I like this one better) I finally put together all the pieces of the puzzle. For whatever reason port 465 and port 587 would not work. This is what worked for me:
Web.config:
<smtp from="pwretrieve#mydomain.com">
<network host="smtp.gmail.com" password="[password]" port="25"
userName="pwretrieve#mydomain.com"/>
</smtp>
from the aspx.cs file:
SmtpClient mSmtpClient = new SmtpClient();
mSmtpClient.EnableSsl = true;
Thanks again!
I had the same problem for my form. My website is running on a Plesk control panel. All I did was to login to my panel and disable email hosting on my web server. After that my form started sending to a Google apps account. Try out what I did, I am sure you will get a difference.
Failing a response from your hosting company and if you have another server you could send test requests to, try requesting connections to other ports and see what happens.
Could be that the smtp client is not able to access the smtp server (might be disabled by the web host).
Ask the web host if they have a specific smtp server you should be using to send emails with.
If your webhost doesn't allow you to send outgoing SMTP mail from their servers, that would cause this problem. For example, GoDaddy only allows you to send outgoing mail through smtpout.secureserver.net from your server, so any attempt to send mail through another host (in this case, smtp.gmail.com) would fail. If your ISP does not block outgoing SMTP (like Qwest does not, for example), then that's why this would work locally.
Check the FAQ with your webhost to see what they have to say about it. Most hosting companies do allow outgoing SMTP, but limit it to a certain number of relays/day, to prevent accidental exploitation for spam forwarding.
You're correct that the MX record on your domain only affects incoming mail. When somebody tries to send mail to you#yourdomain.com, they hand it to an SMTP server (most likely, the one their ISP gives them), and then SMTP server looks up your MX record to see who handles your email. It will resolve to smtp.gmail.com, so that's who will get your mail, and you get it from them. When you send outgoing mail, it can go through anybody, since you only care about the MX record for the destination domain (where the mail will eventually end up).
Does that make sense? If you'd like some clarification, I can find some tutorials and other explanations to help make sense of it.

Categories