Sending email using ASP.NET I am getting this error - asp.net

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. u6sm344516ibd.6
I have my code like this?
MailAddress to = new MailAddress("xxxxx#gmail.com");
MailAddress from = new MailAddress("xxx#gmail.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "Error Occred in the application:";
message.Body = ex.Message;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

the SMTP server required that you use a secure connection
client.EnableSsl = true;

You could check if setting the EnableSsl property for SmtpClient to true and specifying the credentials would help.
client.EnableSsl = true;
client.Credentials = new NetworkCredential("user", "password");

You will need to set the appropriate properties of the SmtpClient instance to enable TSL/SSL, and set credentials. Check out this for more:
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx

Try configuring your SMTP to use port 25 (with SSL).

For gmail Smtp server, use port 587. Port 465 has problems. Make sure you also pass in your correct gmail address and the password that you use with that address/account. Finally, ensure you have set your gmail account to accept connections from other email apps.

Related

Emailing from ASP.NET using Office 365 Online Exchange

Trying to send email from asp.net application.
Emailing to server address: Smtp.office365.com
Port - 587
Connection Security - STARTTLS
I have SMTP user name and SMTP password.
Fails to send email.
The code uses the SmtpClient, as follows:
String userName = "name#example.com";
String password = "Password";
MailAddress RecipientEmail = new MailAddress(EmailTo);
MailAddress SenderEmail = new MailAddress(cEmailFrom);
MailMessage msg = new MailMessage(SenderEmail, RecipientEmail);
msg.Subject = "Test";
msg.Body = "This is a test";
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.office365.com:587");
client.Credentials = new System.Net.NetworkCredential(userName, password);
client.EnableSsl = true;
client.Send(msg);
The error message: Failure sending email. No other information.
But if I specify the port:
client.port = 587
instead of adding it to the host name, I get a very long error:
Transaction failed. The server response was: 5.2.0
STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:BC110000, 17.43559:0000000094000000000000000100000000000000, 20.52176:140FBF85130010100A00D231, 20.50032:140FBF85831710100A00E231, 0.35180:86260000, 255.23226:0A00C931, 255.27962:0A000000, 255.27962:0E000000, 255.31418:0A000000, 16.55847:DC000000, 17.43559:0000000088010000000000001E00000000000000, 20.52176:140FBF85130010109F260000, 20.50032:140FBF8583171010A4260000, 0.35180:0A00D330, 255.23226:A9260000, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:B3260000, 4.21921:DC040000, 255.27962:FA000000, 255.1494:0A007530, 0.37692:02010480, 0.44092:00000000, 0.40348:02010480, 0.34608:04000100, 0.55056:00000000, 0.42768:302E3134, 0.56112:31393A44, 0.52807:30363031, 4.33016:DC040000, 7.40748:010000000000010B2D343438, 7.57132:000000000000000037323032,
What is missing?
The important part from the error is the phrase "SendAsDenied".
Office 365 won't let you use your account on their smtp servers to send e-mail messages from someone else's address. You just can't do it. The closest you can get is in cases of organizational domain accounts, you can sometimes have service accounts within the organization that can be delegated to send on behalf of other users within the organization's domain.
If you need to do more than that, you must manage your own smtp server... and let me tell you, that's a whole other can of worms, requiring an ability to understand and configure some or all of rDNS, SPF, DKIM, Domain-Keys, and DMARC.

Sending email from website WITHOUT using Google SMTP

I am producing a website for a friends company and they would like customers to be able to contact them using a form on the website that will email the query to their work email address.
All the examples I have been able to find use GMail's SMTP server. I have managed to get this to work using the code below but e-mails always appear in the inbox as from the GMail account, regardless of what I set mm.From to be. I understand that this is the downside to using GMail's SMTP server.
Dim mm As MailMessage = New MailMessage()
mm.From = New MailAddress("customer#test.com")
mm.Subject = "Test Email"
mm.Body = "<p>This is a test email</p>"
mm.IsBodyHtml = True
mm.To.Add(New MailAddress("info#myCompany.com"))
Dim smtp As SmtpClient = New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.EnableSsl = True
Dim NetworkCred As NetworkCredential = New System.Net.NetworkCredential()
NetworkCred.UserName = "mycompany#gmail.com"
NetworkCred.Password = "myPassword"
smtp.UseDefaultCredentials = True
smtp.Credentials = NetworkCred
smtp.Port = 587
Try
smtp.Send(mm)
Catch ex As Exception
Response.Write(ex)
End Try
I would like the senders e-mail address to appear in the from field so users can just click reply when a message comes in.
The business e-mail account they have is provided by GoDaddy and I have tried entering the SMTP and account details in the code but I get the following error:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
Any help would be greatly appreciated.
Thanks
You can use any SMTP service that you have access to. So if GMail's doesn't do what you need, try another one. (The settings for that other one may be different, check with the service host for details.)
However, one thing you can definitely do in your code is set a ReplyTo address. From is only one header in the message, there are others that can be used. A ReplyTo header tells the email client that replies should be sent to a given email address.
mm.ReplyTo = New MailAddress("customer#test.com")

We do not relay non-local mail,Mailbox name not allowed. What does it mean

I am trying to send email via System.Net.Mail. On clicking send I am getting the following exception
System.Net.Mail.SmtpFailedRecipientException: Mailbox name not allowed. The server response was: We do not relay non-local mail
MailAddress toAddress = new MailAddress(toEmail);
MailAddress fromAddress = new MailAddress(fromEmail);
MailMessage mailMsg = new MailMessage(fromAddress, toAddress);
mailMsg.Subject = EmailSubject;
mailMsg.Body = MessageBody.ToString();
mailMsg.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtp = new SmtpClient(EmailSettings.SmtpServer);
smtp.Send(mailMsg);
That is all I am doing.
What workaround should I take for this to work
You should authenticate your SMTP client using credentials AND sender mailbox belonging to SMTP server you're connecting to.
Also (depending on your mail server) the fromAddress needs to be an actual account on the mail server.

Yahoo Smtp mailsetting configuration

Does anyone know what the smtp mail configuration settings are that is needed in the web.config file to send outgoing mail through a form in ASP? Thanks.
Check out this link: Yahoo POP3 and SMTP Settings
My guess is the following should work in your code (not exactly sure about credentials as I do not have an account to test with):
MailMessage mail = new MailMessage();
mail.From = new MailAddress("fromname#somewhere.com");
mail.To.Add("toname#somewhereelse.com");
mail.Subject = "The Subject";
mail.Body = "Body text here";
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient smtp = new SmtpClient("smtp.mail.yahoo.com");
smtp.Port = 465; // this could be 587, not sure
smtp.Credentials = new NetworkCredential("YourYahooId", "YourYahooPassword");
smtp.EnableSsl = true; // SSL is required I think
smtp.Send(mail);
The key is to make sure you are using SSL and send authentication credentials. I don't think you will be able to do SSL with just the web.config mail settings. Please see this question for more information.
See the How to utilize Google gmail server in your.NET Web & Windows Applications article. That code work for me. If it doesn't work for you, send mail to me(pandiansaamy#gmail.com)
SMTP_SERVER = "smtp.mail.yahoo.com"
SMTP_PORT = 587
SMTP_USERNAME = "username" // username#yahoo.com
SMTP_PASSWORD = "password"

Email Code Error

In Email code, I get following error.
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Is this indicating that we require SSL certificate ?
This error code means that you need to provide a valid credentials in order to use this smtp server:
var client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new NetworkCredential("youraccount#gmail.com", "secret");

Resources