How to change the email that SES sends from? - amazon-web-services

Right now I have a few domains verified in AWS. I just started using SES with SMTP to send some emails from contact forms/password resets on my site but have run into a bit of an issue.
I have the domain example.com verified and am wanting to send emails from no-reply#example.com but whenever I send them it sends from my work email me#example.com
What can I do to get this setup? I posted on Reddit and was told that I can setup CloudFormation in order to do it but that seems way over complicated for what I'm trying to do. I just want to change the email that it's sent from on a verified domain, I would assume that's pretty simple.
Any help would be great, thanks!

I used SES with the SMTP interface (from a .net application), and because my domains are verified, all I need to do is change the 'FROM' address, and it will send from whichever email address I want.
Here is a code example:
using (var msg = new MailMessage())
{
msg.From = new MailAddress("anything#my-verified-domain.com");
msg.To.Add(s.EmailAddress);
msg.Subject = "Test Subject";
msg.Body = body;
msg.IsBodyHtml = true;
msg.Headers.Add("X-SES-CONFIGURATION-SET", "configset-1");
using (var smtp = new SmtpClient())
{
smtp.Send(msg);
}
}
Maybe if you shared some code we could see where you are going wrong.

Related

Exim, define alternate router for forward mail, by user forward address

I have a problem, I am using the SES AWS service, for the delivery of my email; this works without problems; the problem arises when I want to send forwarding mail from one mailbox to another destination account, receive the following error:
Mailfromuser_sernder#domain.tld
(ultimately generated from usermail_forwarder#domain.tld)
host ses-smtp-us-west-xxxxxxx.xxxxx.us-west-2.elb.amazonaws.com
SMTP error of the remote mail server after the end of the data:
554 Message rejected: the email address is not verified. The following identities could not be verified in the US-WEST-2 region:
Mailfromuser_sernder#domain.tld
Investigate the issue and the reason is that the SRS (Service Rewrite Scheme) is not compatible with SES AWS. reference here.
I asked Cpanel for support because I use the Cpanel on my server, not even a drop of help, they answered that it was a technical problem.
The only solution that think, is forwarder mail by any local user and size is more than 10 mb is sending by another router.
He there my problem, as I define it; in the router section use these lines and it serves only for one domain, he researched and you can read the headers of the email, but I do not know how
sender_redirect:
driver = dnslookup
domains = domain.tld
transport = remote_smtp
no more
I know it's wrong, but I do not know how to declare the functions to do nex requeriments:
That, if is forwarding mail by any mailbox, I sent it by this
router and not by amazon ses
The message is greater than 10 mb, sending by this router and not by
amazon ses

Vapor Client with Authentication

I need to auth on the server that I'm trying to pull data from I currently have it connecting to the server with:
let urlString = "\(makeUrl(grammar: grammar))&\(query)"
let drop = Droplet()
return try drop.client.get(urlString)
But I can't seem to figure out how to get creds attached to the get request. I tried just putting the user and password into the url but found the vapor client doesn't allow that:
/*
Userinfo (i.e., username and password) are now disallowed in HTTP and
HTTPS URIs, because of security issues related to their transmission
on the wire. (Section 2.7.1)
*/
With a little nudge from the Vapor Slack channel and a little code diving in the AlamoFire repo I have found the solution.
First you need to base64 encode the username name and password and then add it to the http header.
func performRequest(query: String, grammar: FMPGrammar) throws -> Response {
let urlString = "\(makeUrl(grammar: grammar))?\(query)"
let loginString = "\(userName):\(password)"
let b64Login = Data(loginString.utf8).base64EncodedString(options: [])
let drop = Droplet()
let result = try drop.client.get(urlString, headers: [.authorization : "Basic \(b64Login)"])
return result
}
Like the error states, it is a HUGE security risk to include username/password credentials in plaintext as GET uri parameters. You should (at a minimum) be sending them in a POST call.
Check out the blog post on User Authentication with Vapor to see a pretty decent example of setting up user authentication with Vapor. The blog is a little old now (Vapor has changed a lot since then), but I think pretty much everything in it should still work. At least conceptually.
Also, you join the Vapor Slack channel and ask questions in there :)
qutheory.slack.com

NET 4.5 HttpClient send cookie anyway (despite changed domain)

I have created an HttpClient in C#
Client = new HttpClient(handler);
The handler is this
var handler = new HttpClientHandler
{
CookieContainer = CookieContainer,
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
};
I send some requests in a site, let's say it is xyzevents.com. I receive my responses normally, I store some cookies I receive from "Set Cookie:*" commands, everything works good.
However, after this I try to communicate with the site xyz.com. In order to do that, I must send my requests, using the cookies I stored from xyzevents.com earlier. The HttpClient can't do that, because it sees the host is different than xyzevents.com.
Is there a way to bypass that check, and send my requests with no problem?
I don't think there's anyway to "disable" this check. I think it's the HttpClient that ends up deciding which cookies should be sent, not the container. And in the end, the security risks that could happen by sending random cookies anywhere are pretty large.
With that, you could easily loop through all the cookies received from xyz.com, create them manually with the domain changed but the same values. Then add them to a new collection which is sent to xyzevents.com.

Override mail settings in application for dev server environments

I am currently in the finishing stages of building an application and have asked the user group to perform production-level usage testing on the application. My application is a makeshift order management system that sends an email to a customer when an order is saved that includes an invoice.
I ran into a problem yesterday when I was doing some testing; this environment currently contains production-quality data, including old customer records. I processed a few orders and forgot about the functionality, and the customer who I did the orders for received emails saying the order is complete. Good that it worked, bad that it lead to this confusion.
The action I would prefer would be to set something somewhere within the application that forces all emails, regardless of the to recipient, to be sent to a specific address, though I would settle for simply being able to turn it off for this application alone. Turning it off on the server level is available not a preferred option due to the need to perform testing on other applications that process email, but are not populated with production-quality data.
Are there any specific flags or code I can use to override server settings in the application to only send email to a certain address based on how we identify our environment, or to not send email altogether?
Reference this page:
http://cookbooks.adobe.com/post_How_can_I_use_Application_level_SMTP_Server_Settin-16469.html
For testing purposes you could set the SMTP server to a non existant IP address. The cfmail routine will still work and coldfusion will move it to an undeliverable folder.
You could add <cfif> statements around it to determine if your on a production URL or dev URL so that it uses the right server while on the production server, or uses the "fake" server while on your development server. OR while on the production server, have an on/off variable that you could use to test emails through your smtp server or shut off emails and route them to the fake SMTP server.
If your on version 8.0 or older, you can setup an application level variable for your mail server and modify your cfmail tags to reference:
<cfmail server="#application.mailserver#" to="" from="" subject="">
This solution presumes you use the same mail server but just want to swap emails to a test address (perhaps yours, so you can see the result). It also presumes your live server name resolves to something that has 'www.something.somethong.' and your dev/test/qa etc servers do not.
In your Application cfc onApplicationStart() try this:
<cfscript>
if(listFirst(CGI.SERVER_NAME,'.') != 'www') {
Application.szEmailToTestEnv = 'test#somewhere.com'; // Use your test email here
}
</cfscript>
Then where you send the email have a bit of logic infront of your mail param such that:
<cfscript>
if(isDefined('Application.szEmailToTestEnv') && len(Application.szEmailToTestEnv)) {
Variables.szEmailTo = Application.szEmailToTestEnv;
} else Variables.szEmailTo = Variables.qCustomerEmail;
</cfscript>
And then in your cfmail:
<cfmail to="#Variables.szEmailTo#"....
Adjust scopes and variable names and value as necessary.
Essentially, any 'site' (say dev.yoursite.com) that is not your live site will then use the test email you set at app startup to send the email and live will continue to use the correct customer email with no code changes between your live and test code.

Django Email backend (keeps sending email from incorrect "sender")

I have several instances in my project where I attempt to send an email within a Django view.
I want to be able to hardcode the email sender within the view. When I try to do so, though, it continues to send the emails from the default account specified in my settings file.
Here is an example:
if testform.is_valid():
beta=testform.save()
subject="Hi Beta Tester"
sender="correct#email.com"
recipient=[testform.cleaned_data['email']]
text=loader.get_template('registration/beta_email.txt')
html=loader.get_template('registration/beta_email.html')
site_name='mysite'
d=Context({'site_name':site_name})
text_content=text.render(d)
html_content=html.render(d)
#This sends two mail versions, plain text and html
msg=EmailMultiAlternatives(subject, text_content, sender, recipient)
msg.attach_alternative(html_content, "text/html")
msg.send()
return HttpResponseRedirect('/splash/')
I thought that I could send specify the sender argument explicitly here. And, yet, when I test it, the email is being sent from the address listed in my settings file, configured as the following:
EMAIL_USE_TLS=True
EMAIL_HOST='smtp.gmail.com'
EMAIL_HOST_USER='wrong#email.com'
EMAIL_HOST_PASSWORD='private'
DEFAULT_FROM_EMAIL='wrong#email.com'
Do I just have to remove the DEFAULT_FROM_EMAIL constant to make it work? I tried doing so and it seems to be working but I'm confused. In the Django documentation, it suggests that setting sender in the view should override the DEFAULT.
I've finally figured out the issue here. Unfortunately, gmail rewrites the from and the
envelope on authenticated smtp.
If you want to get around that, you have to use a third party mail server (which doesn't act like such a prissy) and then send mail to gmail users.
For the sender e-mail try putting it in < > and you can add a name:
sender = "Formal Name <correct#email.com>"
that is exactly the syntax I have in my e-mail sending view and it works.
There really shouldn't be a reason that adding the name to it would change how it's sending, but it may be worth trying and perhaps you want an easily readable name anyway.