I had an working email sending functionality using c#. Suddenly gmail recipients are not getting the mails(neither in inbox nor spam). But other recipients (like outlook or any domain) are getting mails in their inbox.
Here is my code:
SmtpClient SmtpMail = new SmtpClient();
MailMessage myMail = new MailMessage();
System.Text.Encoding myEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
myMail.SubjectEncoding = myEncoding;
myMail.BodyEncoding = myEncoding;
myMail.From = (new MailAddress("Administrator#domain.com", "User Name"));
myMail.To.Add("somemail#gmail.com");
myMail.Subject = "Subject";
myMail.Priority = MailPriority.High;
SmtpMail.Port = 587;
myMail.IsBodyHtml = true;
myMail.Body = "<h1>Hi This is robin</h1>";
SmtpMail.Host = "mail17.ezhostingserver.com";
SmtpMail.EnableSsl = true;
SmtpMail.UseDefaultCredentials = false;
System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("useremail", "password");
SmtpMail.Credentials = basicAuthenticationInfo;
SmtpMail.Send(myMail);
However, I tried to manually send message from their Mail Application to a Gmail user. In that case the recipient is getting the mail. Mails only sent from the code to any gmail user is the main problem here.
NB: I have already tried port:26, SmtpMail.UseDefaultCredentials = true. Still no luck
In my case, google was considering my emails as spammy and blocked the emails for reducing the amount of spam sent to Gmail.
Please visit https://support.google.com/mail/?p=UnsolicitedMessageError for more information
Related
Our application has the possibility to send emails via SmtpClient. One of our customer is trying to do so by using his gmail account and it fails resulting in a timeout. However, from our testing lab it works just fine (with another gmail account).
In the trace i can see that the server is not answering with Certificate, Server Key Exchange, Server Hello Done. And im wondering what can be the cause for this?
I also noticed in the traces, the customer is using TLSv1 so I tried to replicate the error on a Windows7 system but still it works for me.
oSmtp = new SmtpClient(this.host, this.port);
oSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
oSmtp.EnableSsl = ssl;
NetworkCredential oCredential = new NetworkCredential(this.userName, this.password);
oSmtp.Credentials = oCredential;
oSmtp.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
string userState = null;
oSmtp.SendAsync(oMsg, userState);
As far as the code goes, enableSsl is true, the port is 587 and we also instructed our customer to check his gmail account and allow less secure applications.
We will ask the customer for more specific details and try to put more traces in our application, but i would like to know if there is anything that can prevent the server to answer with Certificate,...
Inspecting the traces revealed no significant difference between customers Client Hello and our test Client Hello.
Thanks!
This is a working sample i used few days ago:
string fromAddress = "fromaddress#gmail.com";
var toAddress = new MailAddress("fake#email.com", "To person");
const string fromPassword = "pass";
const string subject = "test";
const string body = "Hey now!!";
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(fromAddress);
mail.To.Add(toAddress);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
//mail.Attachments.Add(new Attachment("C:\\file.zip"));
using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
{
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.EnableSsl = true;
smtp.Send(mail);
}
}
also make sure to enable Less secure app access for the gmail you are using to send data:
I have tried to send email to my client's customers with my client from address(info#myclient.com).
and my client has already configured my smtp server via SPF to their domain.
Following is C# code written to send the email.
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("info#mycient.com");
mail.To.Add("krishna.menan#gmail.com");
mail.Subject = "This is an email";
mail.Body = "this is a sample body with html in it. <b>This is bold</b>
<font color=#336699>This is blue</font>";
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
System.Net.NetworkCredential networkCredentialRFE = new
System.Net.NetworkCredential("kirshna#mycomapny.com", "Password123");
smtp.Credentials = networkCredentialRFE;
smtp.Host = "outlook.office365.com";
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.Send(mail);
Following is error I am getting:
Mailbox unavailable. The server response was: 5.7.60 SMTP; Client does not have permissions to send as this sender
Make sure that the taskuser you are using has the proper "send as" permissions, see "Give mailbox permissions to another user in Office 365 - Admin Help".
I am working on an online shopping website. I want the users directly contact each other via emails by using a web form. I have tried different ways. but it didn't work.
I was also trying to use the gmail smtp as follow:
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential("example#gmail.com", "mypassword");
client.EnableSsl = true;
string fromAddress = "buyer#gmail.com";
string messageSubject = "Your Subject";
string body = "Content";
var supEmail = "seller#yahoo.com";
MailMessage mm = new MailMessage(fromAddress, supEmail, messageSubject, body);
MailAddress copy = new MailAddress("notifications#mydomain.com");
mm.CC.Add(copy);
//Set up your encoding
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.Priority = System.Net.Mail.MailPriority.High;
//Send your message
client.Send(mm);
Any idea or suggestions?
This won't work. Google won't allow you to send an email from an account you don't own... so if you want to send an email via Google then it needs to be from either the Google email account your are validating with or associated with that account.
I am stuck and not able to receive email from yahoo id(if the sender email id is of yahoo).
code is working fine not giving me any error and i am receiving email fromm gmail id.
i am using localhost (not in local machine on live server).
hosting server : smtp.snapgrid.com
also used authentication,enable ssl , using proper port for ssl.
on snapgrid i do check so i got is mail from yahoo is blocked and the message is,
message :
Type: blocked
Reason: 550 5.7.1 Unauthenticated email from yahoo.com is not accepted due to domain's
DMARC policy. Please contact administrator of yahoo.com domain if this was a legitimate
mail. Please visit http://support.google.com/mail/answer/2451690 to learn about DMARC
initiative.
please help...
code i used to send is(its working fine just giving for idea):
Method 1:
SmtpClient objSMTPClient = new SmtpClient();
objSMTPClient.Host = ConfigurationManager.AppSettings["strSMTPServer"];
string BODY_FORMAT = ConfigurationManager.AppSettings["EmailBodyContentFormat"];
MailMessage objMailMessage = new MailMessage(from.Trim(), to.Trim(), subject.Trim(), body.Trim());
objSMTPClient.UseDefaultCredentials = false;
if (BODY_FORMAT.ToUpper() == "HTML")
objMailMessage.IsBodyHtml = true;
else if (BODY_FORMAT.ToUpper() == "TEXT")
{
body = StripTags(body);
objMailMessage.IsBodyHtml = false;
objMailMessage.Body = body.ToString().Trim();
}
else
return false;
objSMTPClient.Send(objMailMessage);
return true;
Method 2:
SmtpClient oMail = new SmtpClient();
MailMessage msg = new MailMessage();
MailAddress Madd = new MailAddress(from, "sunil");
oMail.Host = "smtp.gmail.com";
oMail.Port = 587;
oMail.EnableSsl = true;
oMail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
oMail.Credentials = new NetworkCredential("sunil123#mydomain.com", "******");
oMail.Timeout = 20000;
msg.From = Madd;
msg.Body = body.ToString();
msg.To.Add(to);
msg.Subject = subject;
msg.IsBodyHtml = true;
oMail.Send(msg);
return true;
both are working having no bug running without error....
If you are sending via a server belonging to someone like Yahoo, Google or Office365 they expect the sender name of the account to match that that you're sending using in the from address.
For example, this would work on a your local SMTP server:
Message.From = new MailAddress("GrandMasterFlush#domain.com");
However, to get it to send via someone like Yahoo would require you to send it like this:
Message.From = new MailAddress("GrandMasterFlush#domain.com", "Grandmaster Flush");
If the sender name provided does not exactly match that of the account the email will not get sent.
I want to select file and send to employees.
employee's(recipient) email I am reading from excel.
Sender's email is set to my code.
MailMessage mail = new MailMessage();
mail.Attachments.Add(new System.Net.Mail.Attachment(attach));
mail.To.Add(sendmail);
mail.From = new MailAddress(SenderEmail);
mail.Subject = "Payroll";
string body = "Hi, payroll";
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("sendermail", "pwd");
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Send(mail);
Now I want to read sender's email & password from a textbox,and pass.
Now error occuring like this
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
I coded smtpclient host as gmail and corresponding port.
But I want to send from other account means in yahoo,live etc..
How can it possible? But even gmail is also giving error.Can anybody help?
error is getting when reading from textbox