Issue with Google smtp ASPMX.L.GOOGLE.COM - c#

I couldn't send mail using smtp ASPMX.L.GOOGLE.COM. I have domain domain.co.in and email address test#domain.co.in which is accessible in gmail. i Could send mail manually but not programmatically. throws below error.
Service not available, closing transmission channel. The server response was: 4.7.0 [61.16.142.134 15] Our system has detected that this message is
MailAddress ma_from = new MailAddress("test#domain.co.in", "fromName");
MailAddress ma_to = new MailAddress("jrao.XXXX#gmail.com", "fromName");
string s_password = "TestPwd";
string s_subject = "Test";
string s_body = "This is a Test";
SmtpClient smtp = new SmtpClient
{
Host = "ASPMX.L.GOOGLE.COM",
Port = 25,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(ma_from.Address, s_password)
};
using (MailMessage mail = new MailMessage(ma_from, ma_to)
{
Subject = s_subject,
Body = s_body
})
smtp.Send(mail);

Where did you get those settings? I don't think port 25 will work with SSL. Try port 587 and host "smtp.gmail.com"
The full response from Google would help. Was it perhaps "Our system has detected an unusual rate of unsolicited mail originating from your IP address. To protect our users from spam, mail sent from your IP address has been temporarily rate limited." Note that unless you're using a fixed-line internet connection from home, you're probably sharing an IP address with many other users.
Ensure you have a "strong" password
Ensure the "from" email address is your primary email address and not an alias.

Try Using Port 587
And host "smtp.gmail.com"
Specially You'll need to set your gmail account allow less secure apps to send mails. It's a security concern in gmail.
You can set this setting by folowing this link.
Allow Less Secure Apps
Hope this would help.. :)

Related

Go Daddy email SMTP not sending email but no error

I've recently purchased the essentials email package from GoDaddy and I am trying to set up sending email from my website via SMTP. I have the following code set up.
var smtp = new SmtpClient
{
Host = "mycoolwebsite.com.mail.protection.outlook.com",
Port = 25,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("info#mycoolwebsite.com", "supersecurepassword")
};
using (var message = new MailMessage("info#mycoolwebsite.com", "myemail#test.com")
{
IsBodyHtml = true,
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
This gets to send and doesn't throw any exceptions, however the email is not sent. I am very confused at why this doesn't work.
Has anyone got any ideas?
This is going to require TLS which means using MailKit's SMTP. You can get it using the NuGet package manager in Visual Studio. Search for MailKit by Jeffrey Stedfast.
Documentation is here as well.
Once you have all the references in place, use the MailKit.Net.Smtp.SmtpClient class:
Set "smtp.office365.com" as your host
Use port 587.
You will need to add this line after creating your smtp instance because you have no OAuth token:
smtp.AuthenticationMechanisms.Remove("XOAUTH2");
That will do what you need.
Here's an example of what the whole thing should look like:
string FromPseudonym = "MySite Support";
string FromAddress = "admin#MySite.com";
var message = new MimeMessage();
message.From.Add(new MailboxAddress(FromPseudonym, FromAddress));
message.To.Add(new MailboxAddress("Recipient Pseudonym", "RecipientAddress#somewhere.com"));
message.Subject = "Testing Email";
var bodyBuilder = new BodyBuilder();
string MsgBody = "Message Body stuff goes here";
bodyBuilder.HtmlBody = MsgBody;
message.Body = bodyBuilder.ToMessageBody();
using (var client = new SmtpClient())
{
client.Connect("smtp.office365.com", 587);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate(FromAddress, "Your super secret password goes here");
client.Send(message);
client.Disconnect(true);
}
You'll need the following namespaces to be included:
using MimeKit;
using MimeKit.Utils;
using MailKit.Net.Smtp;
I've been where you are before. If you are running the app from your dev environment, the emails will not be sent. GoDaddy SMTP is configured so that emails will only be sent when requested from within their environment.
If you push the code to their host and run it, it will work. The most painful thing about this is that everything appears to go smoothly, but the SMTP client just eats the request and leaves you wondering why no email is sent.
Not knowing anything about GoDaddy's API, the only thing I can suggest, is maybe verify that the port is correct. It might require transport layer security, in which case port 25 will be closed.
For example, I think the office365 SMTP server (smtp.office365.com) requires secure SMTP and uses port 587.

Gmail Error sending email from application [duplicate]

I want to do an application for sending emails in C# windows application.I used smtp server,but I don't want to set the network credentials. So I set it as true.but am getting error.
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
Here is the code:
SmtpClient oClient = new SmtpClient();
oClient.Host = "smtp.gmail.com";
oClient.Port = 25;
oClient.UseDefaultCredentials = true;
oClient.Credentials = new System.Net.NetworkCredential();
oClient.EnableSsl = true;
MailMessage oMail = new MailMessage();
oMail.To.Add(txtTo.Text.Trim());
oMail.From = new MailAddress("testmail#gmail.com");
oMail.Subject = txtSubject.Text;
oMail.Body = txtBody.Text;
oMail.IsBodyHtml = true;
oClient.Send(oMail);
MessageBox.Show("Mail Send");
here I set the host as gmail.com,I need to send and receive mails using all email service providers.So how can I set the host and port?
gmail uses port 587
oClient.Port = 587;
You may also want to set UseDefaultCredentials to false and explicitly declare username and password. By declaring it to be true, you are trying to log into your gmail account using your windows credentials.
oClient.UseDefaultCredentials = false;
oClient.Credentials = new NetworkCredential("email#gmail.com", "password");
Also, in gmail security, you will need to allow Less Secure Applications.
Finally, you need to change how your Mail.To is populated:
oMail.To.Add(new MailAddress(txtTo.Text.Trim()));
Google may block sign in attempts from some apps or devices when you try to login from some app. You need to go to security settings at your gmail and enable less secure apps . So that you will be able to login from all apps. Go to Allow less secure apps and choose Allow to let less secure apps access your Google account. Have a look at this link may useful.

How do I use Gmail's SMTP client to send an email to myself in C# without enabling access for less secure apps in Gmail settings?

I'm working on an ASP.NET Web Forms app and I'm trying to programmatically send an email to myself. I'm using Gmail's SMTP client, and all is well except that when I send my message, I get this error:
"System.Net.Mail.SmtpException: 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"
If I go into my gmail account settings and enable an option that allows me to allow access for "less secure apps", everything works fine. I'm wondering how I can send my email with having this option enabled.
protected void sendEmail(object sender, EventArgs e)
{
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new System.Net.NetworkCredential("myusername#gmail.com", "mypassword"),
DeliveryMethod = SmtpDeliveryMethod.Network,
EnableSsl = true
};
MailAddress from = new MailAddress("myusername#gmail.com", "Torchedmuffinz");
MailAddress to = new MailAddress("myusername#gmail.com", "Torchedmuffinz");
MailMessage message = new MailMessage(from, to);
message.Subject = "test";
message.Body = "test";
Attachment attachFile = new Attachment(#"pathtofile");
message.Attachments.Add(attachFile);
try { client.Send(message); }
catch (Exception email_exception)
{
System.Diagnostics.Debug.WriteLine(email_exception);
}
}
Gmail port 587 does not support SSL.
I think the following code should work for you.
MailMessage msg = new MailMessage();
msg.From=new MailAddress("yourmail#gmail.com");
msg.To.Add("receiver#receiverdomain.com");
msg.Subject="Your Subject";
msg.Body="Message content is going to be here";
msg.IsBodyHtml=false; //if you are going to send an html content, you have to make this true
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port=587;
NetworkCredential credential=new NetworkCredential("yourmail#gmail.com","your gmail password");
client.UseDefaultCredentials=false;
client.Credentials=credential;
client.Send(msg);
There is a possibility to use Google SMTP servers without 'Allow less secure apps' option, but you cannot use your standard google username and password. See my instructions on other post:
Is there a way to use ASP.NET to send email through a Google Apps acccount without selecting the 'Allow less secure apps' option?

Cannot send email through Hotmail / live.com / outlook.com

I have read other answers on the stackoverflow. but none of the solutions work for me.
I'm trying to send email through live.com, but unable to it.
The error message:
mailbox unavailable. The server response was: 5.7.3 requested action aborted;
user not authenticated
or error message:
System.Net.Mail.SmtpException: Service not available,
closing transmission channel.
The server response was: Cannot connect to SMTP server 65.55.176.126
(65.55.176.126:587), NB connect error 1460
The code:
MailMessage mail = new MailMessage();
mail.From = new MailAddress("email#live.com");
mail.To.Add("someone#someone.com");
mail.Subject = "hello";
mail.Body = "awefkljj kawefl";
mail.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient("smtp.live.com", 587);
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("email#live.com", "password");
smtp.Send(mail);
Are you able to send the email by using above code?
It works before, last year, but it is no more working now.
I'm not sure what has been changed to live.com email server.
What new settings or parameters should apply?
I ran into an issue where I was unable to send emails using the smtp.live.com SMTP server from certain hosts -- particulary Azure hosts. In my case, the SMTP attempt was from a host that I had never used to sign-in previously, so the attempt was blocked with the 5.7.3 error:
Mailbox unavailable. The server response was: 5.7.3 requested action aborted; user not authenticated
The solution was to browse to the account settings, locate the SMTP request in its recent activity, and select "This was me":
Tested and it works (different host address and a few other property set):
using (var client = new SmtpClient("smtp-mail.outlook.com")
{
Port = 587,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
EnableSsl = true,
Credentials = new NetworkCredential(_sender, _password)
})
{
using (var mail = new MailMessage(_sender, _recipient)
{
Subject = _subject,
Body = _message
})
{
client.Send(mail);
}
}
Also, if the account has two-step verification turned on, you'll have to generate an app password and use that instead.
Your code works for me without any changes with a live.com address. I am able to generate the same exception by simply putting an incorrect password.
I would suggest following checks:
Did the user change password recently? Are you able to login with the credentials provided over the web interface?
if yes, does your program uses the exact same credentials? please note that white space can be your enemy.

Sending an Email through gmail SMTP Server (SSL)

I know there's a lot of example on how to send an email using C# but I am really running into some issues and I can't make it to work.
I always get "Failure sending mail" error, Unable to connect to the remote server - No connection could be made because the active machine actively refused it (IP address here).
What does this error mean? And how do I fix this?
Any help will be much appreciated
Here's the code that I've been using: (although I already did try a lot of things)
string SendersAddress = "test#gmail.com";
string ReceiversAddress = "test1#gmail.com";
const string SendersPassword = "test-pass-here";
const string subject = "Testing";
const string body = "Hi This Is my Mail From Gmail";
try
{
SmtpClient smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(SendersAddress, SendersPassword),
Timeout = 3000
};
MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);
smtp.Send(message);
}
catch (Exception ex)
{
}
Thanks!
It sounds like you're running into issues connecting to the SMTP server.
Make sure the firewall is open on port 25, and that you actually have an SMTP server running wherever you're trying to establish your connection.
You're trying to establish an SSL connection to gmail on port 587. That port must be used with TLS, not SSL.
Use port 465 instead.
Also note that the Timeout property is expressed in milliseconds, so 3000 can be a little short, depending on your network. Try using a more permissive value, like 30000.
Also worth checking that your anti-virus is not blocking port 25, I have been caught by that before!
Same for me in past few days,
Easy solution:
First check if everything is OK with Telnet, then try to do the same in C#.
Here is a good intro : http://www.wikihow.com/Send-Email-Using-Telnet.
Just beware that some servers use the EHLO command instead of HELO
EDIT:
take a look at the way that you can connect to SMTP server of Google here

Categories

Resources