As titled, is it possible to get Email Address from SMTP server by User name and password?
The reason I want to do this is because I know some smtp server supports open relay and some don't, for that reason, I see no meaning to provide the Sender and From email address.
But in the SmtpClient class it requires a Sender and From Email email address.
Instead I want to do it by getting the actual Email Address which is the User name associated to in the SMTP server.
Is it possible to do this?
Related
Hi does anyone know how to send or reply to an outlook mailitem using a specific string of email address?
FOR EXAMPLE:
my outlook email address is:
string email = "myOutlookEmailAddress#company.com";
now instead of my outlook email address, i want to use (email address from a specific mailbox on my outlook):
string email = "otherEmailAddress#company.com";
I already tried using this:
Outlook.Accounts accounts = application.Session.Accounts;
foreach (Outlook.Account account in accounts)
{
// When the e-mail address matches, return the account.
if (account.SmtpAddress == smtpAddress)
{
return account;
}
}
but its only looking up for the accounts on what is in my outlook application.
If you are sending through Exchange on behalf of another mailbox, set the MailItem.SentOnBehalfOfName property (assuming you have sufficient privileges)
If you are sending through a particular SMTP account, set the MailItem.SendUsingAccount property.
If you need to send as an arbitrary SMTP user, see this example on my website - you will essentially need to set the "From" named MAPI property in the PS_INTERNET_HEADERS namespace. Note that not all SMTP servers will let you do that - Exchange for one will not let you spoof the sender.
If you want to send as one of the alias (proxy) SMTP addresses belonging to a particular Exchange mailbox, you will need to send through SMTP - sending through OOM or MAPI will always send with the default SMTP address of the mailbox. For an end user, you can configure a dummy POP3/SMTP account or use a product like Proxy Manager (I am its author). See MSOutlook.info for more information.
On contact us page fields are name, email address and message.
That details send to specified mail address with entered mail address in the form.
Is it possible with gmail smtp details.
smtp details as below
Host: smtp.gmail.com
Username: *****#gmail.com
Password: ********
Port: 25
Gmail doesn't allow you to change the FROM to something different than your gmail account.
It doesn't matter what you use, they over-write it, before they relay it on. This prevent spamming/spoofing.
I created this email address "info#mydomain.com" and I want users be able to send email for me through my website.
Here is my code:
MailMessage mailObject = new MailMessage("a#b.com(this is fake email)", "info#mydomain.com", "contact us", "Test message");
SmtpClient smtpC = new SmtpClient("smtp server name");
smtpC.Send(mailObject);
Problem is I dont know what to write for smtp server name. How can I find what is my smtp server name?
This is the address of the SMTP server you want to use. e.g. smtp.gmail.com if you're using Gmail.
Search you email or hosting provider's website for "SMTP". Most likely they will have the details (smtp server name, port, ssl or not) soewhere in the FAQs.
Mostly the SMTP Server Name should be smtp.mydomain.com
Still it is best to contact the hosting provider
Open up a command prompt (CMD.exe)
Type nslookup and hit enter
Type set type=MX and hit enter
Type the domain name and hit enter, for example: google.com
The results will be a list of host names that are set up for SMTP
i am creating an email client that sends e-mail address from server ip instead of SMTP , i wrote that code:
SmtpClient server = new SmtpClient("50.23.128.66");
MailMessage msg = new MailMessage("from#yahoo.com", "tome#yahoo.com", "subject", "body");
server.Send(msg);
but when i run it , i get that error:
Unhandled Exception: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Relaying Denied.
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressColl
ection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
* By the way i am using Windows Server 2008 *
and i configured the smtp server to localhost and port 25 , but i don`t know what is that relying error .
If you are using you localhost to rely email, you should be using 127.0.0.1 or localhost instead of that ip address you posted in your code.
Relaying is the method the SMTP server uses to authenticate that it should route the email from a particular sender. An "open relay" means that there is no authentication and the SMTP server will send email sent from anyone. This is not a good practice and there are probably some mechanisms on this particular SMTP server to authenticates, such as a user name and password or even the IP address of the sender. Check with the administrator of the SMTP server to see what is required. I would think at a minimum you would need to set the user name and password, which you did not do in your code example.
I have used the following code to send mail from my web application using a gmail account. My question is, can i change the sender address to another address other than original sender(gmail) address?
My code is as follows:
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("sample#gmail.com", "*******");
Whatever i do is useless as i always receive mail from sample#gmail.com. Is it possible to change it?
I have changed to
mail.From = new System.Net.Mail.MailAddress("sample#yahoo.com"); but i received the mail with the from address sample#gmail.com and not from the new "From" address. I think gmail smtp overwrites the from address with the original credential.
This is the solution:
use the codes above to set mail.From = new MailAddress(address, display name)
in Gmail, go to Mail Settings >> Accounts and Import.
Add the email account you will use as sender in "Send Mail As". (tick as Alias)
This works for me
Gmail doesn't allow you to change the FROM to something different than your gmail account.
It doesn't matter what you use, they over-write it, before they relay it on. This prevent spamming/spoofing.
Yes just use the From property of the MailMessage
eg.
mail.From = "newemail#email.com";
EDIT: Also, see this post for more detailed info on how to emails via gmail in C#
Sending email in .NET through Gmail
EDIT: Although this works for mail in general, it appears this won't work for gmail as google overwrite it before its sent (see #Dave wanta's answer)
If you have a limited number of senders you can do as #philip suggested. For instance you may have customerservice#example.com, simon#example.com and philip#example.com or even alias#example.com. As long as they are approved senders on the actual gmail.com website you can send from them.
Gmail.com : Sending mail from a different address
If you are expecting to send from an arbitrary user (such as a customer service form on a website where the user enters their email and you don't want them emailing you directly) about the best you can do is this :
msg.ReplyToList.Add(new System.Net.Mail.MailAddress(email, friendlyName));
If you're in a controlled environment this works great, but please note that I've seen some email clients send to the from address even when reply-to is specified (I don't know which).
Check #56 and #58. They might be relevant to what you want to do
https://code.google.com/p/google-apps-script-issues/issues/detail?id=172