How to send the email through mine company email id
Like every company use to give some email id to its associates like xyz#abc.com
How to send the mails through this id to other accounts. Also I don't have passwords for this id, then how to send the email in this situation.
You could use the SmtpClient class. Other than the from and to addresses you will need your company's SMTP server:
var message = new MailMessage();
message.To.Add("to#abc.com");
message.Subject = "This is the Subject";
message.From = new MailAddress("from#abc.com");
message.Body = "body of the mail";
using (var smtpClient = new SmtpClient("smtp.abc.com"))
{
smtpClient.Send(message);
}
Related
I have project related school management system in c# using asp.net as framework and sql server as database.
I need to send email with same email body and subject (like: wish you a very happy new year) but i have different from addresses and obviously different to addresses.
For example: i need to send email to all teachers with aa#aa.aa email and to all students with bb#bb.bb email address and to management staff with cc#cc.cc
How can i perform this task in c# and asp.net with efficient way?
You can create SmtpClient and MailMessage object in order to send email.
I think you should call your mail sending method with 3 times with different parameters (from address and receivers list) Your methos looks like
SendMail("aa#aa.aa", teacherList);
SendMail("bb#bb.bb", studentList);
SendMail("cc#cc.cc", staffList);
public static void SendMail(string fromAddress, List<string> emailAddresses)
{
//make this smtpClient global. Because you will use next time.
SmtpClient smtpClient = new SmtpClient();
smtpClient.Credentials = new System.Net.NetworkCredential("smtpUserName", "smtpPassword");
smtpClient.Host = "mail.mailhost.com";//set your smtp host. Generally mail.domain.com
smtpClient.Port = 587;//set your smtp port
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = false;//you can change this based on your settings
MailMessage mail = new MailMessage();
mail.From = new MailAddress(fromAddress, "Our School Name");
for (int i = 0; i < emaillAddresses.Count; i++)
{
mail.Bcc.Add(new MailAddress(emaillAddresses[i]));
}
mail.Subject = "Wish you a very happy new year";
mail.IsBodyHtml = true;
mail.BodyEncoding = System.Text.Encoding.UTF8;
smtpClient.Send(mail);
}
I am attempting to send an email using the SendGrid library: https://github.com/sendgrid/sendgrid-csharp
More specifically I am doing this...
// Create the email object first, then add the properties.
SendGridMessage myMessage = new SendGridMessage();
myMessage.AddTo("anna#example.com");
myMessage.From = new MailAddress("john#example.com", "John Smith");
myMessage.Subject = "Testing the SendGrid Library";
myMessage.Text = "Hello World!";
// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential("username", "password");
// Create an Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
transportWeb.DeliverAsync(myMessage);
The code runs fine however I never receive an email!! How do I diagnose this problem?
Note the email doesn't appear in the Bounces/Blocks/Spam Reports or Invalid Email lists.
I know that this is an old post, but here's my answer:
SendGrid is not used for receiving emails to your email address, only to send them in mass. If you want to use I suggest using SmtpClient from MailKit. Be sure to use the proper hostname, like smtp.gmail.com, a port number, like 465 for SSL, and the proper credentials (Username and password of any email address).
One thing to note, if you use your own credentials for your own email address and you want to send it to that same email address, like if you want to send an email to JoeBlank#email with it's own credentials, you will only send to yourself. If you want to reply back to a different email address, fill in the ReplyTo field. The idea is to let the email of the authorized email address send you the message. Here's the code:
using MimeKit;
using MailKit.Net.Smtp;
MimeMessage message = new MimeMessage();
message.From.Add(new MailboxAddress("Sender Name", "sender#example.com"));
message.To.Add(new MailboxAddress("Receiver Name", "receiver#example.com"));
message.ReplyTo.Add(new MailboxAddress("ReplyTo Name", "replyto#example.com"));
message.Subject = "Subject";
message.Body = new TextPart("plain")
{
Text = plainTextContent
};
using (SmtpClient smClient = new SmtpClient())
{
smClient.Connect("smtp.gmail.com", 465, true);
smClient.Authenticate("user", "pass");
await smClient.SendAsync(message);
smClient.Disconnect(true);
}
I'm using smtp (c#)and trying to send mail to group id(official id) but its not able to send mail.Although through same code I'm able to send mail to individual id. Any idea what could be wrong here.
Following code I'm using
MailMessage mail = new MailMessage();
mail.To = "group#company.com";
mail.From = "me#company.com";
mail.Subject = "Test Mail: please Ignore";
mail.Body = body;
SmtpMail.SmtpServer = "mailhub.int.company.com";
SmtpMail.Send(mail)
I'm getting following error in my mail box:
Delivery has failed to these recipients or distribution lists:
group#company.com
Not Authorized. You are not authorized to send to this recipient or distribution list. For distribution lists please check approved senders in the corporate directory.
_____
Sent by Microsoft Exchange Server 2007
Diagnostic information for administrators:
Generating server: GSPWMS005.int.company.com
group#company.com
#550 5.7.1 RESOLVER.RST.AuthRequired; authentication required ##
From error I could get an idea that some authentication is missing but not sure which one or how to resolve it.
If I send mail to this group thorough my outlook then its working ok.
http://msdn.microsoft.com/en-us/library/59x2s2s6.aspx
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test e-mail message sent by an application. ";
message.Subject = "Test Email using Credentials";
NetworkCredential myCreds = new NetworkCredential("username", "password", "domain");
CredentialCache myCredentialCache = new CredentialCache();
try
{
myCredentialCache.Add("ContoscoMail", 35, "Basic", myCreds);
myCredentialCache.Add("ContoscoMail", 45, "NTLM", myCreds);
client.Credentials = myCredentialCache.GetCredential("ContosoMail", 45, "NTLM");
client.Send(message);
Console.WriteLine("Goodbye.");
}
catch(Exception e)
{
Console.WriteLine("Exception is raised. ");
Console.WriteLine("Message: {0} ",e.Message);
}
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");
smtpClient.Credentials = new NetworkCredential("xxxxx#gmail.com", "password");
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
//mail.From = new MailAddress("xxx1#gmail.com");
mail.To.Add("XX2#gmail.com");
mail.Subject = "Test mail";
mail.Body = "This is test mail, with test content";
smtpClient.Send(mail);
In the above code, why mail.From is mandatory? even I specified mail-id in smtpClient.Credentials.
Even I specified mail.From with some mail-id, the receiver is not receiving mail from this mail address, instead receiving from xxxxx#gmail.com which I specified in smtpClient.Credentials.
From is supposed to be the address from where the mail was sent.
This can be different from your Smtp credentials. Some servers will let you have a username that is different from your mail address.
Gmail shows the email address from where it received the mail.
They do that so that users don't mistake getting the mail from someone who didn't really send it.
Not all email clients do that.
You cannot fake a from address to gmail. They will always show where they got the email from.
I am trying to create a contact us page where visitor of the site can leave a message to site-admin.
say I m running this site
www.example.com
and i have an id contact#example.com
Now a new visitor visits my site and fills up the contact us form.
He fills
FROM - abc#yahoo.com
Subject- Query
Message- My question....
I want to send this message as a mail to contact#example.com
And on successfull sending of mail i want to send this user autogenerated mail as an acknowledgement.
What I need to do for this, My hosting server is GoDaddy
I am trying the following code.
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(txtEmailId.Text);
mailMessage.To.Add(new MailAddress("contact#example.com"));
mailMessage.Subject = txtSubject.Text;
mailMessage.Body = txtMessage.Text;
mailMessage.IsBodyHtml = false;
mailMessage.Priority = MailPriority.High;
SmtpClient sc = new SmtpClient("relay-hosting.secureserver.net");
//sc.Credentials = new System.Net.NetworkCredential("contact#example.com", "MyPassword");
sc.Send(mailMessage);
}
catch (Exception ex)
{
Label1.Text = "An Error has occured : "+ex.Message;
}
This error occurs while trying to send mail.
Mailbox name not allowed. The server
response was: sorry, your mail was
administratively denied. (#5.7.1)
It looks like from your code you are specifying that the mail message's From field is based on the email address the user fills in. The mail server mail be rejecting this and only allowing email from the domain name example.com or perhaps the server name itself. I've run into this before where your From field must be the original site domain...
If you want to have the ability for the form-mail recipient to directly reply, use the ReplyTo field rather than the from:
MailMessage mailMessage = new MailMessage();
//try using a domain address that matches your server and/or site.
//the email address itself may also have to exist depending on the mail server.
mailMessage.From = new MailAddress("no-reply#example.com");
//set the replyto field
mailMessage.ReplyTo = new MailAddress(txtEmailId.Text);
//send the mail...
Hope this might help...
EDIT:
After you've edited your question, the above is still relevant. It's very likely you cannot use a From address outside of your own site domain example.com. If you want to send two copies of the request (one to contact#example.com and the other to the user as an acknowledgment), you simply need to add to the To property:
MailMessage mailMessage = new MailMessage();
//try using a domain address that matches your server and/or site.
//the email address itself may also have to exist depending on the mail server.
mailMessage.From = new MailAddress("abc#example.com");
//add the contact email address to the To list
mailMessage.To.Add(new MailAddress("contact#example.com"));
//add the user email address to the To list
mailMessage.To.Add(new MailAddress(txtEmailId.Text));
//set the replyto field
mailMessage.ReplyTo = new MailAddress(txtEmailId.Text);
//send the mail...
If you need to add a simple message for the user acknowledgment email you could also do:
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("abc#example.com");
mailMessage.To.Add(new MailAddress("contact#example.com"));
mailMessage.ReplyTo = new MailAddress(txtEmailId.Text);
mailMessage.Subject = txtSubject.Text;
mailMessage.Body = txtMessage.Text;
mailMessage.IsBodyHtml = false;
mailMessage.Priority = MailPriority.High;
SmtpClient sc = new SmtpClient("relay-hosting.secureserver.net");
//sc.Credentials = new System.Net.NetworkCredential("contact#example.com", "MyPassword");
//send to only the contact#example.com first
sc.Send(mailMessage);
mailMessage.To.Clear();
mailMessage.To.Add(new MailAddress(txtEmailId.Text));
//add a simple message to the user at the beginning of the body
mailMessage.Body = "Thank you for submitting your question. The following has been submitted to contact#example.com: <br/><br/>" + mailMessage.Body;
//send the acknowledgment message to the user
sc.Send(mailMessage);
}
catch (Exception ex)
{
Label1.Text = "An Error has occured : "+ex.Message;
}
It is probably Serverfault.com question, any how
you need to check these options
Admin Home -> Configuration -> Email
Options -> - E-Mail Transport Method =
sendemail
reference 553 sorry, your mail was administratively denied. (#5.7.1)