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.
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 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.
I am trying to send mail through SMTP but i am getting the error unable to connect remote server, I have tried alot but still getting same error
I am hosted my site on Go Daddy,
please any body suggest me where i am wrong , or is there any settings on GoDaddy server to send mail from "relay-hosting.secureserver.net"
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
message.To.Add(toList);
System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient("
relay-hosting.secureserver.net", 25);
Client.Credentials = CredentialCache.DefaultNetworkCredentials;
Client.DeliveryMethod = SmtpDeliveryMethod.Network;
Client.Send(message);
You are trying to send mail using remote SMTP server, but using credentials from your local environment.
Try to use another credentials class type to specify it more concrete:
Client.Credentials = new System.Net.NetworkCredential("yourusername", "yourpassword");
Referring to your code:
System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient("
relay-hosting.secureserver.net", 25);
You're using port 25, which is actually the problem. System Administrators who utilize GoDaddy as their hosting provider may experience trouble sending mail over port 25. This is because GoDaddy requires their servers to send through their own SMTP Relay instead of any third party. This is really a frustration situation, but this is what Godaddy policy is. If you use Godaddy relay, then it will work.
I am developing a web application for my company. Part of it requires the internal user to fill out a form, and send an email on this user's behalf. It is all within the company. I searched and found two possible routes old system.net.mail and a more recent microsoft.exchange.webservices, but seems our exchange server requires credentials. I can only get the user's login and his email address login+"#company.com". How can i get this done?
Below are the codes i used smtp (system.net.mail), but it doesnt work.
string[] username =System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\');
string email = username[1] + "#company.com";
MailAddress from = new MailAddress(email);
MailAddress to = new MailAddress("someone#company.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "testmail";
message.Body = "<h>testmail</h>";
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(message);
SmtpClient requires that you either specify the SMTP server directly, or that you have the right application/machine configuration settings for it to detect the server automatically. Your code is choosing the second option implicitly, and I suspect you don't have the right settings in app/machine config. Exchange does NOT support SMTP in its default configuration, afaik, so unless someone familiar with your Exchange server knows SMTP is configured and can give you the right address, SmtpClient is probably out.
Exchange Web Services (aka EWS) is probably your better answer, but it's not really a good one. In order to use exchange web services, you will need one of:
1) The domain, username, and password of the user so that you can pass the right NetworkCredential to EWS. In your case, this would probably mean the user has to enter their password into your form, which may break your requirements.
2) The user that the process is running as (in a web application, the application pool identity for IIS) has to have permissions to send mail as the user in question.
3) If you can use ASP.NET authentication to impersonate the user (this would only be a good approach in a LAN application), then you can effectively fall back to option (2), because now you will be talking to EWS as the user, who obviously will have permission to send mail from their own address.
As you can see, the right approach depends greatly on your Exchange/Active Directory/LAN setup.
i am trying to send email from c# windows application and i need SMTP Server Address to send email but i don't know about SMTP Server Address, what is SMTP Server Address, how to get SMTP Server Address and how to use it.
this is the code:
System.Web.Mail.MailMessage message=new System.Web.Mail.MailMessage();
message.From="from e-mail";
message.To="to e-mail";
message.Subject="Message Subject";
message.Body="Message Body";
System.Web.Mail.SmtpMail.SmtpServer="SMTP Server Address";
System.Web.Mail.SmtpMail.Send(message);
What Mail Server are you trying to use??? usually you can just google SMTP or POP3 or whatever protocal your looking for and it will give you the port, server and all the extra information you need to connect to it.
For example:
http://support.google.com/mail/bin/answer.py?hl=en&answer=13287
First, the System.Web.Mail namespace utilities are marked as 'obsolete' and should not be used. Instead, you should use System.Net. In that namespace there is a 'MailMessage' and an 'SmtpClient' class that will do the job you are trying to do.
Next, an SMTP server is a process that runs on a computer, which, when connected to the inetrnet, can listen for, and respond to, incoming requests which use a particular protocol on a particular port. You can think of an SMTP server as the machine at the post office that sorts and routes the mail to the appropriate mailbox..
An SMTP server has an address, just like everything else on the internet that needs to communicate with anything else. The address is used to send your mail message to the right machine, on the right communication channel. you could think of it as its phone number, and your mail message a text that will be sent to it.
Next, the address you are looking for, last time I checked, was: smtp.gmail.com.
So, considering that you need to stop using System.Web.Mail, and considering that your address may be smtp.gmail.com, here is what your code should look like:
// setup mail message
MailMessage message = new MailMessage();
message.From = new MailAddress("from e-mail");
message.To.Add(new MailAddress("to e-mail"));
message.Subject = "Message Subject";
message.Body = "Message Body";
// setup mail client
SmtpClient mailClient = new SmtpClient("smtp.gmail.com");
mailClient.Credentials = new NetworkCredential("youraccount#gmail.com", "yourGmailPassword");
// send message
mailClient.Send(message);
Also, here is a decent looking article on using gmail as your smtp server:
How to use Gmail as your SMTP server
Also, if gmail does not work for you, you can use the smtp server of your internet provider. They will usually have their smtp address lurking on their website somewhere to be helpful to customers who want to setup their email program. You can also look in Outlook under account settings if you cannot find it somewhere else, if you use anything besides gmail, you should find one there.
Lastly, keep in mind, email cannot be sent without using an smtp server which is willing to receive and dispatch your maill message. In general this is something like gmail, or the smtp server of your internet provider, and the address will normally be: smtp.providername.com. However, gmail, for example, requires your account credentials for the smtp server to allow your message to be received and dispatched.