Email with SendGrid is not working in Azure Apps - asp.net

I need to send email from my code using the below code snippet. It is working fine in my code, but when I deploy the code in microsoft azure I am getting an error as follows.Kindly help me to rectify the issue.
MailMessage mail = new MailMessage();
mail.From = new MailAddress(FromAddress);
mail.To.Add(email);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient SmtpServer = new SmtpClient("smtp.sendgrid.net");
SmtpServer.Port = 587;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential myCreds = new NetworkCredential(EmailUsername, EmailPassword);
SmtpServer.EnableSsl = true;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = myCreds;
SmtpServer.Send(mail);
Error as Follows

Finally I found a Solution, I have written some code for getting OS version and Browser version. That was creating issue.

Related

ASP.NET how to write code for mail sender?

I have search many sites. But I can't understatnd what they said. Refer in internet they told to create CDO files.
Please help me to send mail in my Project. I have 3 textboxes:
Tomail
Heading
Content of the message
Send Button
Use Below Code to sent mail.
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("me#mydomain.com");
mail.To.Add("u#urdomain.com,rkrishtring#gmail.com");
mail.Subject = "Report";
mail.Body = "This is a Stack overflow using report";
Attachment attachment = new Attachment(filename);
mail.Attachments.Add(attachment);
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);

Sending Email from gmail from localhost through Asp.net

Sometimes following code sends Email,Sometimes i get SMTP Exception saying "failure in sending Email".Why is this happening? following is the code i have written.Plesae tell me why sometime i get email sent and sometime why i get Exception.
StringBuilder mailBody = new StringBuilder();
mailBody.Append("Hi <br/>")
MailMessage message = new MailMessage("from#gmail.com", "to#gmail.com");
message.Subject = "Subject";
message.Body = mailBody.ToString();
SmtpClient smtpclient = new SmtpClient("smtp.gmail.com", 587);
smtpclient.Credentials = new System.Net.NetworkCredential()
{ UserName = "from#gmail.com",
Password = "password"
};
smtpclient.EnableSsl = true;
message.IsBodyHtml = true;
smtpclient.Send(message);

I can't send email in asp .net

When i send email there is an exception which says "failure sending mail".
var mailObj = new MailMessage("marabifuad2013#gmail.com", "to Email");
mailObj.Subject = "subject";
mailObj.Body ="";
mailObj.IsBodyHtml = true;
var smtpServer = new SmtpClient("smtp.gmail.com", 587);
smtpServer.Credentials = new NetworkCredential("marabifuad2013#gmail.com", "password");
smtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpServer.Send(mailObj);
I guess that because you haven't specified to use SSL:
smtpServer.EnableSsl = true;
Also you can try:
smtpServer.UseDefaultCredentials = true;
Apart from that everything looks fine, providing that you entering correct credentials and etc.

How to send mail with asp.net

When a customer buys an item, the button should send an email to the website owner. Here is the code I currently have:
SmtpClient smtpClient = new SmtpClient("smtpout.europe.secureserver.net", 80);
smtpClient.Credentials = new System.Net.NetworkCredential("info#furkantellioglu.com ", "Password");
smtpClient.UseDefaultCredentials = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.Body = "Bekleyen Siparişleriniz Bulunmakta Lütfen Kontrol Ediniz.";
mail.Subject = "Dermabon Web Satış";
mail.IsBodyHtml = true;
mail.From = new MailAddress("info#furkantellioglu.com", "Sipariş");
mail.To.Add(new MailAddress("info#furkantellioglu.com"));
mail.CC.Add(new MailAddress("f.tellioglu#gmail.com"));
smtpClient.Send(mail);
But when I run it I get this error:
An exception of type 'System.Net.Mail.SmtpException' occurred in System.dll but was not handled in user code
Additional information: Sunucu güvenli bağlantıları desteklemiyor.
Any ideas on what this means?
please try changing
smtpClient.EnableSsl = true;
to
SmtpServer.EnableSsl = false;
a similar thread has been discussed on this forum which might help you Link
the error message means the server does not support secure connections. Your are using enable ssl but sending to port 80 so there could be a conflict here.
seems like a port error, try using changing
EnableSsl=false; and or UseDefaultCredentials = true; or use port 25

Sending e-mail in ASP .Net

How to send e-mail on ASP .Net using outlook address??
I've tried this code but no luck:
Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
mailMessage.From = New System.Net.Mail.MailAddress("fromAddress")
mailMessage.To.Add(New System.Net.Mail.MailAddress("toAddress"))
mailMessage.Priority = Net.Mail.MailPriority.High
mailMessage.Subject = "Subject"
mailMessage.Body = "test"
Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient("xxx.outlook.com", portNumber)
smtpClient.Send(mailMessage) //--> got error here
But while I'm execute the code, it got this error message:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
I've tried to add a line of code:
smtpClient.Credentials = New System.Net.NetworkCredential(username, password)
But still can't send the e-mail.
Anyone can help?
Try smtpClient.UseDefaultCredentials = false; before you set new Credentials
Try to set smtpClient.EnableSsl to true / false depending on your environment
I'm guessing you are using Exchange 2007 or later as backend?
Anyway, your mail server does not allow you to send mails anonymously. You'll either need to supply a username/password in your code or allow unauthenticated relaying from your webserver.
Talk to your IT guys what they prefer.
I did it using c#.This may help you.Please check.
MailMessage msg1 = new MailMessage();
msg1.From = strEFrom;
msg1.To = strETo;
msg1.Cc = strECC;
msg1.Subject = "Hi";
msg1.Priority = MailPriority.High;
msg1.BodyFormat = MailFormat.Html;
msg1.Body = strBody;
SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["MailServer"].ToString();
SmtpMail.Send(msg1);
and in web.config file
<appSettings>
<add key="MailServer" value=""/>
</appSettings>
Try these settings check for .EnableSSL property to true/false and the smtp post number on which your mail server listen for outgoing mail.
When you do not set enable the SSL settings in outlook for gmail outlook configuration then it gives same error but the reason was found the SSL settings..
well try this may it will solve your problem..
msg.IsBodyHtml = true;
msg.Body = mailContent;
SmtpClient mailClient = new SmtpClient("smtp.mail.yahoo.com", 25);
NetworkCredential NetCrd = new NetworkCredential(frmyahoo, frmpwd);
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = NetCrd;
mailClient.EnableSsl = false;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mailClient.Send(msg);
if it does not solve your problem then check your mail server/ client for the problem.
public static bool SendMail(string mailAccount, string password, string to, string subject, string message)
{
try
{
NetworkCredential loginInfo = new NetworkCredential(mailAccount, password);
MailMessage msg = new MailMessage();
msg.From = new MailAddress(from);
msg.To.Add(new MailAddress(to));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = false;
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);
return true;
}
catch (Exception)
{
return false;
}
}
I use this code to send mail from my gmail account.
was having the same error, moved the client.UseDefaultCredentials = false; before setting client.Credentials and everything works.

Resources