Parallels Webmail issue - c#

I know maybe my question is some strange but I want to send email from asp.net web project to my registered clients. I can do this using gmail so easily. but I want send it from Parallels Webmail.
my C# code is like this:
using (MailMessage mm = new MailMessage("info#mydomain.com", email))
{
mm.Subject = "Account Activation";
string body = "Hello " + name.Trim();
mm.Body = body;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "mydomain.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("info#mydomain.com", "mypassword");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 26;//587 is also tested
smtp.Send(mm);
}
But I get error "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 74.63.251.194:26"
I am sure I can't send right smtp.host format.
this is only setting for email client on paralles
The screen shot of error message is here too:
Any comments are appreciated.

Use port 25 and make smtp.EnableSsl = true;
using (MailMessage mm = new MailMessage("info#mydomain.com", email))
{
mm.Subject = "Account Activation";
string body = "Hello " + name.Trim();
mm.Body = body;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = false;
smtp.Host = "mydomain.com";
NetworkCredential NetworkCred = new NetworkCredential("info#mydomain.com", "mypassword");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 25;
smtp.Send(mm);
}

Related

Why do I get an error by trying to send a mail with c#?

I'm trying to send an e-mail using C#, but I get this recurring error :
.
Can you explain me what's wrong with my code ?
Here it is :
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.EnableSsl = true;
client.Timeout = 100000;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("myEmailAdress#gmail.com", "myPassword");
MailMessage msg = new MailMessage();
msg.To.Add("receiver#gmail.com");
msg.From = new MailAddress("sender#gmail.com");
msg.Subject = "My subject";
msg.Body = "My body";
client.Send(msg);
MessageBox.Show("Message sent !");
I have encountered same before.
You are getting this error because you haven't set ON on Less secure app access for sender#gmail.com as you are using Gmail SMTP port.
Reason:
Your email has no remotely access permission. You have to configure
it. Suppose you want to sent email from sender#gmail.com so you
have set that permission NO to this account.
How To Set:
You could try like below
Or can open that tab from this link directly Less secure app access
Update:
As per your comment this is for you which has working perfectly since the beginning of my career
public object SendMail(string fromEmail, string toEmail, string mailSubject, string mailBody, string senderName, string senderPass, string attacmmentLocationPath)
{
try
{
MailMessage mail = new MailMessage();
//Must be change before using
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(fromEmail);
mail.To.Add(toEmail);
mail.Subject = mailSubject;
mail.Body = mailBody;
mail.IsBodyHtml = true;
// mail.Attachments.Add(new Attachment(#attacmmentLocationPath));
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential(senderName, senderPass);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
return true;
}
catch (Exception ex)
{
return ex;
}
}
Hope that would help.
This code works for gmail, it is very similar to yours with slight differences, but if you try this, and it doesn't work for you, the issue is not the code - perhaps some other network related issue that you are going to need to fix first:
using (var msg = new MailMessage())
{
msg.From = new MailAddress("fromaddress#gmail.com");
msg.To.Add("toaddress#gmail.com");
msg.Subject = subject;
msg.Body = body;
msg.IsBodyHtml = true;
using (var smtp = new SmtpClient())
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("xxx#gmail.com","password");
smtp.Send(msg);
}
}
An SMTP client may log in using an authentication mechanism chosen among those supported by the SMTP servers.

How can I use Google to send email? [duplicate]

I am getting an error when trying to send an e-mail through my web service. I have tried enabling access to less secure apps disabling 2-step verification and logging into the account via a web browser. None of the solutions on SO have worked for me. I am still getting:
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.
What can I do to fix this issue?
namespace EmailService
{
public class Service1 : IService1
{
public string SendEmail(string inputEmail, string subject, string body)
{
string returnString = "";
try
{
MailMessage email = new MailMessage();
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
// set up the Gmail server
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("myemail#gmail.com", "mypassword");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
// draft the email
MailAddress fromAddress = new MailAddress("cse445emailservice#gmail.com");
email.From = fromAddress;
email.To.Add(inputEmail);
email.Subject = body;
email.Body = body;
smtp.Send(email);
returnString = "Success! Please check your e-mail.";
}
catch(Exception ex)
{
returnString = "Error: " + ex.ToString();
}
return returnString;
}
}
}
Just Go here : Less secure apps , Log on using your Email and Password which use for sending mail in your c# code , and choose Turn On.
Also please go to this link and click on Continue Allow access to your Google account
also I edit it little bit :
public string sendit(string ReciverMail)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("YourMail#gmail.com");
msg.To.Add(ReciverMail);
msg.Subject = "Hello world! " + DateTime.Now.ToString();
msg.Body = "hi to you ... :)";
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = true;
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential("YourMail#gmail.com", "YourPassword");
client.Timeout = 20000;
try
{
client.Send(msg);
return "Mail has been successfully sent!";
}
catch (Exception ex)
{
return "Fail Has error" + ex.Message;
}
finally
{
msg.Dispose();
}
}
If the above code don't work , try to change it like the following code :
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("YourMail#gmail.com", "YourPassword");

Server busy, closing transmission channel. Try again later while sending mail in ASP.NET

I want to send mail. I have following code which was working perfectly. But since few days, I am getting following error.
Error: Service not available, closing transmission channel. The server response was: Server busy, closing transmission channel. Try
again later
Code:
try
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
using (MailMessage mm = new MailMessage("xxx#gmail.com", "yyy#gmail.com"))
{
mm.Subject = "Registration Successfully";
mm.Body = "You are registered successfully. Welcome.";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("xxx#gmail.com", "password");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
}
catch (Exception)
{
throw;
}
I have read following blogs and tried but didnt work.
1- Email alerts -while sending mail to multiple user 1 by 1 getting error as server busy
2- Send Bulk Email From Yahoo and Hotmail Using ASP.Net
don't use SMTP smtp.gmail.com some times create problem
best solution
mm.Subject = "Registration Successfully";
mm.Body = "You are registered successfully. Welcome.";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "domainname.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("demo#domainname.com", "password");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);

ASP.NET - Error sending email Messages

I checked other questions, and i was able to resolve some errors in my code, but smtp.Credentials = nc; , where nc is my Network credentials, is throwing an exception, Request action aborted on MFE proxy, SMTP server is not available.
Please, any help would be appreciated. Below, is my code :
MailMessage msg = new MailMessage();
msg.From = new MailAddress("fromemail");
msg.To.Add("toemail");
msg.Subject = "Contact Us";
msg.Body = cname.Text + "sent me this message" + cmessage.Text + "with this email, " + email.Text;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential nc = new NetworkCredential();
nc.UserName = "fromemail";
nc.Password = "fromemailpwd";
smtp.Credentials = nc;
smtp.Port = 587;
smtp.Send(msg);
sPanel.Visible = true;
lblSuccess.Text = "Success! Thanks for contacting us, we will get back to you soon.";
I changed the smtp.Credentials = nc to smtp.Credentials = new NetworkCredentials("fromemail", "fromemailpwd");
Now, it is this line, smtp.Send(msg), that is throwing the exception.
I wasn't able to get the same error message that you saw, but check out this answer : Request action aborted on MFE proxy, SMTP server is not available
However, I do know that Gmail requires EnableSSL = True

Unable to connect to remote server while sending email in asp.net

The above error arising while using email sending code my code is
string fromAddress = "mymail";
string fromPassword = "mypassword";
var smtp = new System.Net.Mail.SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
smtp.Send(fromAddress, toAddress, MailSubject, Body);
I googled many times but didnt get proper solution.
Port 587 is enbled and firewall blocking also not there.
try
{
MailMessage mail = new MailMessage();
mail.To.Add("sender id");
mail.From = new MailAddress("your id");
mail.Subject = "Mail from my web page";
mail.Body ="Body Content";
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
//Or your Smtp Email ID and Password
smtp.Credentials = new System.Net.NetworkCredential
("XYZ", "XXXXX");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Send(mail);
}
catch (Exception ex)
{
//display exception
}
This code work for me.Try this.
MailMessage mM = new MailMessage();
mM.From = new MailAddress("YourGmail#gmail.com");
mM.To.Add(Email);
mM.Subject = "Your Sub";
mM.Body = "Your Body" ;
mM.IsBodyHtml = true;
mM.Priority = MailPriority.High;
SmtpClient sC = new SmtpClient("smtp.gmail.com");
sC.Port = 587;
sC.Credentials = new NetworkCredential("YourGmail", "YourPassword");
//sC.EnableSsl = true;
sC.EnableSsl = true;
sC.Send(mM);
Thanks for the response.I got solution as
if you are using any antivirus software check it's log to see whether it is because of the antivirus. I faced same problem when McAffee was blocking my mails (there is a security policy - Prevent mass mailing worms from sending mails). Edit this policy and add your application to the exception list. In my case this sorted the problem. Please check if it works for you.
I use following code for Gmail:
Function SendMail_Gmail(ByVal strFrom As String, ByVal strTo As String, ByVal strSubject As String, ByVal strBody As String) As Boolean
Dim mailmsg As New System.Net.Mail.MailMessage()
mailmsg.From = New MailAddress(strFrom)
mailmsg.To.Add(strTo)
mailmsg.Subject = strSubject
mailmsg.IsBodyHtml = True
mailmsg.Body = strBody
mailmsg.Priority = System.Net.Mail.MailPriority.Normal
Dim client As New System.Net.Mail.SmtpClient()
client.Host = "smtp.gmail.com"
client.Port = "587"
client.Credentials = New System.Net.NetworkCredential("youremailid#gmail.com", "Yourpassword")
client.EnableSsl = True
Dim userstate As Object = mailmsg
client.Send(mailmsg)
Return True
End Function

Categories