I have configured my application in Azure web apps. I am sending the mail using smtp server. The outlook is sending emails properly. Other mail providers like(Gmail) are not sending emails. Please help.
Other mail providers like(Gmail) are not sending emails
You could check the providers that have policy to allow to do that.
Take gmail for example, as Ankit Kumar mentioned that you need to turn Allow less secure apps: on for your gmail account.
I also test it on my side, it works correctly. The following is my demo code.
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Tom Gmail", "xx#gmail.com"));
message.To.Add(new MailboxAddress("Tom Hotmail", "xxx#hotmail.com"));
message.Subject = "I am a mail subject";
message.Body = new TextPart("plain")
{
Text = "I am a mail body."
};
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
client.Authenticate("sunguiguan#gmail.com", "#WSX3edc");
client.Send(message);
client.Disconnect(true);
}
We also could use SendGrid on the Azure,more detail please refer to How to Send Email Using SendGrid with Azure.
Related
I want to send email in Azure Function. I write down below code. It works properly in console app & I am able to send email using the credentials. But when I tested the same code in Azure Function it throws me below error.
Exception while executing function: Functions.HttpTriggerCSharp. Microsoft.Azure.WebJobs.Script: One or more errors occurred. f-HttpTriggerCSharp__-1774598883: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [DB6P189CA0021.EURP189.PROD.OUTLOOK.COM]
The code I used -
SmtpClient client = new SmtpClient("smtp-mail.outlook.com");
string _sender = "--email--";
string _password = "-password---";
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(_sender, _password);
client.EnableSsl = true;
client.Credentials = credentials;
string recipient = "--test#outlook.com--";
string subject="Temperature of device exceeds";
string message="Temperature of device exceeds";
try
{
var mail = new MailMessage(_sender.Trim(), recipient.Trim());
mail.Subject = subject;
mail.Body = message;
client.Send(mail);
}
catch (Exception ex)
{
}
I use a queuetrigger and follow your code in my azure function(v1) and it works well.
The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
This message indicates that the SMTP server configured in your Outgoing Mail Account is connecting to an SMTP client submission endpoint which cannot be used for direct send.
Configure your Exchange SMTP to direct send.
Configure the email notification In the DS-Client > setup > configuration > notification Selected SMTP, add the SMTP server settings and selected add the SMTP server settings
Server require authentication.
Add the office365 authenticated account information in the SMTP server authentication window.
Refer to the following Microsoft articles for more information:
Fix issues with printers, scanners, and LOB applications that send email using Office 365
How to set up a multifunction device or application to send email using Office 365
I developed an ASP.net application that can send an email to any domain.
I'm using a simple .Net smtp client:
var fromAddress = new MailAddress("mymailid#gmail.com");
var fromPassword = "xxxxxx";
var toAddress = new MailAddress("yourmailid#yourdoamain.com");
var smtpClient = new System.Net.Mail.SmtpClient
{
Host = "smtp.gmail.com",// or any others
Port = 587, // correspond to host
EnableSsl = true,
DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
smtpClient.Send(message). But I cannot authenticate to any modern mail providers(including gmail, yahoo, yandex) by using .Net.Mail because I have got the following exception The server response was: 5.5.1 Authentication Required
All of the smtp configuration fill-out correctly.
How can I use DotNetOpenAuth for authentication and .Net.Smtp for sending emails?
Please give me an example.
I'd consider your SMTP server. Is it allowing you to send email? Is your request making it to the server and being validated? Have you looked at the traffic using Fiddler?
You can sign up for a free account with SendGrid, who will provide you with a SMTP server to send the email for you. You really are better of using a company like SendGrid instead of the gmail SMTP server.
Other than that, Mail4Net might help you in your code.
To use GMail as a SMTP Server, you have to set some values:
Outgoing Mail (SMTP) Server: smtp.gmail.com
Use Authentication: Yes
Use Secure Connection: Yes (this can be TLS or SSL depending on your mail client)
Username: your GMail account, i.e. user#gmail.com
Password: your GMail password
Port: 465 or 587
You can also move your connection to the web or app config file:
<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="network" from="pam#gmail.com">
<network
host="smtp.gmail.com"
port="465"
enableSsl="true"
userName="pam#gmail.com"
password="password"
/>
</smtp>
</mailSettings>
</system.net>
</configuration>
OK, I know I am adding a lot of answers, but here are my findings after looking at this for several hours:
The error is the client is not authenticated (5.5.1)
I got the same error, then I noticed an email in my inbox (the gmail account is seldom used) saying Someone tried to sign in to your Google Account xxxxx#gmail.com from an app that doesn't meet modern securty standards.
Is you app blocked by google: http://security.google.com/settings/security/activity might show your app, but are you getting an email?
Also, if the account uses 2 step authentication, the email will not be sent without setting an application specific password: https://support.google.com/accounts/answer/185833
I think this is account configuration instead of a problem with your code.
This code works for me, once the email and credentials are updated:
try
{
var message = new MailMessage();
message.Subject = "Test email";
message.Body = "This is a test message";
message.From = new MailAddress("from#email.com");
message.To.Add(new MailAddress("to#email.com"));
var client = new SmtpClient
{
Host = "smtp.sendgrid.com",
Port = 587,
Credentials = new NetworkCredential("User_Name", "My_Password")
};
client.Send(message);
}
catch (Exception ex)
{
var msg = ex.Message;
}
Make sure your SendGrid credentials are correct.
From the comments, I can see the image, showing what you are trying to do:
However, you cannot know what the configurations are going to be and users will select configurations that are not correct. What will you do if the user selects TLS, but there is no TLS support from the mail server?
I think you need to add a Send Test Email button, to send a test email to check the configuration. You can then show any errors that are encountered.
I am developing an ASP.NET website using Visual studio 2010 ultimate. I want to send mail for confirmation to the clients using my yahoo mail account. How can I do so ? what settings should I change or add ?
Here is the Yahoo mail settings
Yahoo! Mail SMTP server address: smtp.mail.yahoo.com
Yahoo! Mail SMTP user name: Your full Yahoo! Mail email address
(including "#yahoo.com")
Yahoo! Mail SMTP password: Your Yahoo! Mail password
Yahoo! Mail SMTP port: 465
Yahoo! Mail SMTP TLS/SSL required: yes
Here is a sample code to send email using yahoo mail settings
SmtpClient emailClient = new SmtpClient("smtp.mail.yahoo.com");
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("xyz#yahoo.com","*******");
emailClient.EnableSsl = true;
emailClient.Credentials = SMTPUserInfo;
emailClient.Port = 465;
MailMessage message = new System.Net.Mail.MailMessage("xyz#gmail.com", "someone#something.something", "fire!!", "Call up 911 and inform my house is on fire and my phone too");
emailClient.Send(message);
You need to have smtp/pop access to yahoo mail in order to send the mail using yahoo account. The free account offered by yahoo does not have that access. You might have to opt for yahoo mail pro.
For sending a mail using SMTP, all you need is username and password of an smtp account. You will use the pass this credentials and send the mail with classes system.net.mail namespace.
You can check this project:
http://www.codeproject.com/Articles/1684/Sending-Mail-Using-C-via-SMTP
There you will see how to setup configuration to send a mail using any (in your case yahoo) smtp server to send an email.
We have an application that prompts the user to login using his ldap username and password, from that I can get the user email but not the email password, My goal is to send email from this user's mail without the need to prompt the user for his email password.
I am using the following code to send email
NetworkCredential loginInfo = new NetworkCredential("fromemail#mydomain.com","mypassword");
MailMessage msg = new MailMessage();
sg.From = new MailAddress("fromemail.lb#mydomain.com");
msg.To.Add(new MailAddress("toemail.lb#mydomain.com"));
msg.Subject = "test";
SmtpClient client = new SmtpClient("smtp.mydomain.com");
client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Credentials = loginInfo;
client.Send(msg);
IS is is possible to send email without password? some thing like email spoofing, If not possilbe, is it possible to fake it, like send all emails form one email, but make the email look as if it is coming from the logged in user's email?
Thanks
It all depends on the SMTP server. When you configure the SMTP server you decide what credentials it accepts and whether it allows you to pretend to be someone you're not. Many web-servers have a built in SMTP server at localhost which usually doesn't require any credentials. Some ISPs provide an SMTP server which allows you to send email from other people. If your SMTP server does not require authentication you can simply remove the 3 lines of code which configure security for the smtp client.
I am trying to write code to send a simple mail from asp.net page.
Confusion is over what to write under "smtp server", when I want to send mail using Microsoft Outlook 2007.
Two sets of code I'm trying:-
1.)
MailMessage objMail = new MailMessage();
objMail.From = "angenlina.jolie#compnayabc.com";
objMail.To = "brad.pitt#companyabc.com";
objMail.BodyFormat = MailFormat.Text;
objMail.Priority = MailPriority.High;
objMail.Subject = "Hi Sweetheart";
string smtpadd = "USA-LA-MAIL1.corp.hollwood.com";
SmtpMail.SmtpServer = "smtpadd";
SmtpMail.Send(objMail);
2.)
SmtpClient smtp = new SmtpClient();
smtp.Port = 25;
smtp.Host = "USA-LA-MAIL1.corp.hollwood.com";
smtp.Credentials = new NetworkCredential("username", "password");
MailMessage email_msg = new MailMessage();
email_msg.To.Add("brad.pitt#companyabc.com");
email_msg.From = new MailAddress("angenlina.jolie#companyabc.com");
email_msg.Subject = "test mail...";
email_msg.Body = "Hi SweetHeart";
email_msg.IsBodyHtml = false;
smtp.Send(email_msg);
Now my problem is what server name should I use for Microsoft outlook 2007(MS exchange server)?
Now my problem is what server name should I use for Micrsoft outlook 2007(MS exchange server)?
Are you sending email via MAPI (using their "Outlook profile") or via SMTP through an Exchange Server? They're not the same.
If you are sending through Exchange then the server will need to be configured to relay mail via SMTP. In which case, put the Exchange server in as the SMTP server.
If you're sending email via MAPI then you'll be using whatever mail server is configured in their "Outlook profile". Which could be SMTP, IMAP, Webmail (with a Hotmail connector or Gmail connector) or Exchange Server.
EDIT:
It sounds like you want to use the Exchange server via MAPI. Here is a good primer to the technologies involved.
Bear in mind that if you're configuring MAPI profiles from within the ASP .NET application you're going to pay attention to the service account the ASP .NET application runs as and that the MAPI is sometimes interactive and not suitable for service based applications.
You may be better off having an administrator configure the Exchange server to route email via SMTP (which is most likely is, unless you have a spam appliance in front of the server which handles SMTP).
try something generic i.e
Email Client setup information
IMAP server: imap.smtpserver.in
POP server: pop.smtpserver.in
SMTP server: smtp.smtpserver.in
Webmail
To access your email through a web browser visit http://webmail.smtpserver.in
smtpserver.in is your smtpserver host address.