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.
I am facing some unexpected problem in sending email which i have never faced before. I have hosted my application on the MyASP.NET server.
My Email Domain is purchased from VERIO.
I am sending mails using by my application, which is hosted on MYASP.NET server.
It means I am trying to connect VERIO SMTP server for sending mails from MYASP.NET server.
It is not giving me any error on sending mail click button from my application. but also email is not going to recipient.
The code which I am using are as follows:
MailMessage mail = new MailMessage();
mail.From = new MailAddress("museum#essenrfid.net");
mail.To.Add(txtTo.Text);
//set the content
mail.Subject = "Test Subject";
mail.Body = "TEst Contect";
//send the message
SmtpClient smtp = new SmtpClient("smtp.verio.com", 587);
smtp.EnableSsl = true;
//IMPORANT: Your smtp login email MUST be same as your FROM address.
NetworkCredential Credentials = new NetworkCredential("XXXXx", "XXXXX");
smtp.Credentials = Credentials;
smtp.Send(mail);
NOTE: My email was working till yesterday from last one month but I have not changed code & it was not working from yesterday. What could be the issue. Any Idea anyone faced this problem before.
Please help.
Thanks In advance.
I am getting this error while sending email from my application. Can anyone suggest any solution.
Service not available, closing transmission channel. The server
response was: 4.3.2 Service not available, closing transmission
channel
Below is code.
string adminID = "AAA#tu.edu";
MailMessage msg = new MailMessage();
msg.From = new MailAddress(adminID);
msg.To.Add("BBB#ttu.edu");
msg.Subject = "Sample Email";
msg.Body = "Hello ";
SmtpClient SmtpMail = new SmtpClient();
SmtpMail.Host = "basic.smtp.ttu.edu";
SmtpMail.Port = 25;
SmtpMail.Send(msg);
Got the solution for the issue. The Server was rejecting the request because this application didn't have write rights on that server. The code was perfectly fine, just it was permissions problem. Hope this helps someone!
Please check whether the server which is sending the e-mail is whitelisted on the SMTP server or Exchange server.
I had the same issue and whitelisting it on SMTP server resolved my issue.
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.
//Create Mail Message Object with content that you want to send with mail.
System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("dotnetguts#gmail.com", "myfriend#yahoo.com",
"This is the mail subject", "Just wanted to say Hello");
MyMailMessage.IsBodyHtml = false;
//Proper Authentication Details need to be passed when sending email from gmail
System.Net.NetworkCredential mailAuthentication = new
System.Net.NetworkCredential("dotnetguts#gmail.com", "myPassword");
//Smtp Mail server of Gmail is "smpt.gmail.com" and it uses port no. 587
//For different server like yahoo this details changes and you can
//get it from respective server.
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
//Enable SSL
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.Send(MyMailMessage);
Thats my code & it throws error :
No connection could be made because the target machine actively refused it 72.14.213.109:587
Code Reference : here
Please tell me how can i sought it out ??
Check both of the following points
1- Check that this port 587 is open on your machine
2- Check if your antivirus is blocking the connection to your port
Regards.
If your have any antivirus software running, check the access protection, unblock "prevent mass mailing worms from send mail"
Did you actually change the username and password?